Exemple #1
0
    def handle_app(self, app, **options):
        using = options.get('database', DEFAULT_DB_ALIAS)
        connection = connections[using]

        app_name = app.__name__.split('.')[-2]
        self.style = no_style()

        sql_list = sql_reset(app, self.style, connection)

        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, connection.settings_dict['NAME']))
        else:
            confirm = 'yes'

        if confirm == 'yes':
            try:
                cursor = connection.cursor()
                for sql in sql_list:
                    cursor.execute(sql)
            except Exception, e:
                transaction.rollback_unless_managed()
                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))
            transaction.commit_unless_managed()
Exemple #2
0
    def handle_app(self, app, **options):
        # This command breaks a lot and should be deprecated
        import warnings

        warnings.warn(
            "This command has been deprecated. The command ``flush`` can be used to delete everything. You can also use ALTER TABLE or DROP TABLE statements manually.",
            DeprecationWarning,
        )
        using = options.get("database", DEFAULT_DB_ALIAS)
        connection = connections[using]

        app_name = app.__name__.split(".")[-2]
        self.style = no_style()

        sql_list = sql_reset(app, self.style, connection)

        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, connection.settings_dict["NAME"])
            )
        else:
            confirm = "yes"

        if confirm == "yes":
            try:
                cursor = connection.cursor()
                for sql in sql_list:
                    cursor.execute(sql)
            except Exception, e:
                transaction.rollback_unless_managed()
                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)
                )
            transaction.commit_unless_managed()
    def handle_app(self, app, **options):
        from django.db import connection, transaction
        from django.conf import settings
        from django.core.management.sql import sql_reset

        app_name = app.__name__.split('.')[-2]

        self.style = no_style()

        sql_list = sql_reset(app, self.style)

        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.DATABASE_NAME))
        else:
            confirm = 'yes'

        if confirm == 'yes':
            try:
                cursor = connection.cursor()
                for sql in sql_list:
                    if sql[:10] == 'DROP TABLE':
                        sql = sql[:-1] + " CASCADE;"

                    cursor.execute(sql)
                    
#                    if dTable:
#                        cursor.execute("select tablename from pg_tables where tableowner='db_2008_07_12'")
#                        for row in cursor.fetchall():
#                            print "row = %s" % (row)
            
            except Exception, e:
                transaction.rollback_unless_managed()
                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))
            transaction.commit_unless_managed()
Exemple #4
0
    def handle_app(self, app, **options):
        connection = connections['default']
        self.style = no_style()
        custom_reset_statements = sql_reset(app, self.style, connection)
        cursor = connection.cursor()
        def execute_sqlreset():
            failed_statements = []
            for sql in custom_reset_statements:
                print 'statement>>>> ' + sql
                try:
                    cursor.execute(sql)
                except Exception,e:
                    if e[0] == 1025:
                        failed_statements.append(sql)

            if failed_statements:
                print "These statements failed: "
                for s in failed_statements:
                    print s
Exemple #5
0
    def handle_app(self, app, **options):
        # This command breaks a lot and should be deprecated
        import warnings
        warnings.warn(
            'This command has been deprecated. The command ``flush`` can be used to delete everything. You can also use ALTER TABLE or DROP TABLE statements manually.',
            DeprecationWarning)
        using = options.get('database', DEFAULT_DB_ALIAS)
        connection = connections[using]

        app_name = app.__name__.split('.')[-2]
        self.style = no_style()

        sql_list = sql_reset(app, self.style, connection)

        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, connection.settings_dict['NAME']))
        else:
            confirm = 'yes'

        if confirm == 'yes':
            try:
                cursor = connection.cursor()
                for sql in sql_list:
                    cursor.execute(sql)
            except Exception, e:
                transaction.rollback_unless_managed()
                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))
            transaction.commit_unless_managed()
    def handle_app(self, app, **options):
        from django.db import connection, transaction
        from django.conf import settings
        from django.core.management.sql import sql_reset

        app_name = app.__name__.split('.')[-2]

        self.style = no_style()

        sql_list = sql_reset(app, self.style)

        if options.get('interactive'):
            confirm = 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.DATABASE_NAME))
        else:
            confirm = 'yes'

        if confirm == 'yes':
            try:
                cursor = connection.cursor()
                for sql in sql_list:
                    cursor.execute(sql)
            except Exception as e:
                transaction.rollback_unless_managed()
                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))
            transaction.commit_unless_managed()
        else:
            print("Reset cancelled.")
Exemple #7
0
 def handle_app(self, app, **options):
     return u'\n'.join(sql_reset(app, self.style, connections[options.get('database')])).encode('utf-8')
Exemple #8
0
 def handle_app(self, app, **options):
     from django.core.management.sql import sql_reset
     return u'\n'.join(sql_reset(app, self.style)).encode('utf-8')
Exemple #9
0
 def handle_app(self, app, **options):
     from django.core.management.sql import sql_reset
     return u'\n'.join(sql_reset(app, self.style)).encode('utf-8')