示例#1
0
 def handle_app(self, app, **options):
     from django_sqlalchemy.backend import metadata
     from sqlalchemy import create_engine
     buf = StringIO()
     def buffer_output(s, p=""):
         return buf.write(s + p)
     engine = create_engine(settings.DJANGO_SQLALCHEMY_DBURI,
         strategy="mock",
         executor=buffer_output)
     sql.reset(engine, app)
     sql.create(engine, app)
     # the sql printed may *not* be the exact sql SQLAlchemy uses. i bet
     # it is pretty close.
     print buf.getvalue()
示例#2
0
 def handle_app(self, app, **options):
     # TODO: figure why this import *has* to be here. it is probably a
     # python related thing i don't fully understand yet.
     from django_sqlalchemy.backend import metadata
     buf = StringIO()
     def buffer_output(s, p=""):
         return buf.write(s + p)
     engine = create_engine(settings.DJANGO_SQLALCHEMY_DBURI,
         strategy="mock",
         executor=buffer_output)
     sql.create(engine, app)
     # the sql printed may *not* be the exact sql SQLAlchemy uses. i bet
     # it is pretty close.
     print buf.getvalue()
示例#3
0
    def handle_app(self, app, **options):
        from django.conf import settings
        from sqlalchemy import create_engine

        app_name = app.__name__.split(".")[-2]
        if options.get("interactive"):
            confirm = raw_input(
                """
You have requested a database reset.
This will IRREVERSIBLY DESTROY any data for
the "%s" application in the database "%s".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """
                % (app_name, settings.DJANGO_SQLALCHEMY_DBURI)
            )
        else:
            confirm = "yes"

        if confirm == "yes":
            try:
                from django_sqlalchemy.backend import metadata

                engine = create_engine(settings.DJANGO_SQLALCHEMY_DBURI)
                sql.reset(engine, app)
                sql.create(engine, app)
            except Exception, e:
                raise CommandError(
                    """Error: %s couldn't be reset. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run.
The full error: %s"""
                    % (app_name, app_name, e)
                )