Ticket #24876: force-generating-sql.diff

File force-generating-sql.diff, 5.9 KB (added by Marcin Nowak, 9 years ago)

Patch proposal

  • core/management/commands/sql.py

    diff --git a/core/management/commands/sql.py b/core/management/commands/sql.py
    index 1b3b1af..841c9f5 100644
    a b class Command(AppCommand):  
    1515        parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
    1616            help='Nominates a database to print the SQL for. Defaults to the '
    1717                 '"default" database.')
     18        parser.add_argument('--force', default=False, action='store_true',
     19                help='Skip migrations checking')
    1820
    1921    def handle_app_config(self, app_config, **options):
    2022        if app_config.models_module is None:
    2123            return
    2224        connection = connections[options['database']]
    23         statements = sql_create(app_config, self.style, connection)
     25        statements = sql_create(app_config, self.style, connection,
     26                options['force'])
    2427        return '\n'.join(statements)
  • core/management/commands/sqlall.py

    diff --git a/core/management/commands/sqlall.py b/core/management/commands/sqlall.py
    index 0a2b9c3..d216482 100644
    a b class Command(AppCommand):  
    1515        parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
    1616            help='Nominates a database to print the SQL for. Defaults to the '
    1717                 '"default" database.')
     18        parser.add_argument('--force', default=False, action='store_true',
     19                help='Skip migrations checking')
    1820
    1921    def handle_app_config(self, app_config, **options):
    2022        if app_config.models_module is None:
    2123            return
    2224        connection = connections[options['database']]
    23         statements = sql_all(app_config, self.style, connection)
     25        statements = sql_all(app_config, self.style, connection,
     26                options['force'])
    2427        return '\n'.join(statements)
  • core/management/commands/sqlindexes.py

    diff --git a/core/management/commands/sqlindexes.py b/core/management/commands/sqlindexes.py
    index ee1f395..2d62f95 100644
    a b class Command(AppCommand):  
    1515        parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
    1616            help='Nominates a database to print the SQL for. Defaults to the '
    1717                 '"default" database.')
     18        parser.add_argument('--force', default=False, action='store_true',
     19                help='Skip migrations checking')
    1820
    1921    def handle_app_config(self, app_config, **options):
    2022        if app_config.models_module is None:
    2123            return
    2224        connection = connections[options['database']]
    23         statements = sql_indexes(app_config, self.style, connection)
     25        statements = sql_indexes(app_config, self.style, connection,
     26                options['force'])
    2427        return '\n'.join(statements)
  • core/management/sql.py

    diff --git a/core/management/sql.py b/core/management/sql.py
    index a189705..864b394 100644
    a b from django.utils.deprecation import RemovedInDjango19Warning  
    1313from django.utils.version import get_docs_version
    1414
    1515
    16 def check_for_migrations(app_config, connection):
     16def check_for_migrations(app_config, connection, force=False):
    1717    # Inner import, else tests imports it too early as it needs settings
    1818    from django.db.migrations.loader import MigrationLoader
    1919    loader = MigrationLoader(connection)
    20     if app_config.label in loader.migrated_apps:
     20    if app_config.label in loader.migrated_apps and not force:
    2121        raise CommandError(
    2222            "App '%s' has migrations. Only the sqlmigrate and sqlflush commands "
    2323            "can be used when an app has migrations." % app_config.label
    2424        )
    2525
    2626
    27 def sql_create(app_config, style, connection):
     27def sql_create(app_config, style, connection, force=False):
    2828    "Returns a list of the CREATE TABLE SQL statements for the given app."
    2929
    30     check_for_migrations(app_config, connection)
     30    check_for_migrations(app_config, connection, force)
    3131
    3232    if connection.settings_dict['ENGINE'] == 'django.db.backends.dummy':
    3333        # This must be the "dummy" database backend, which means the user
    def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_  
    140140    return statements
    141141
    142142
    143 def sql_custom(app_config, style, connection):
     143def sql_custom(app_config, style, connection, force=False):
    144144    "Returns a list of the custom table modifying SQL statements for the given app."
    145145
    146     check_for_migrations(app_config, connection)
     146    check_for_migrations(app_config, connection, force=force)
    147147
    148148    output = []
    149149
    def sql_custom(app_config, style, connection):  
    155155    return output
    156156
    157157
    158 def sql_indexes(app_config, style, connection):
     158def sql_indexes(app_config, style, connection, force=False):
    159159    "Returns a list of the CREATE INDEX SQL statements for all models in the given app."
    160160
    161     check_for_migrations(app_config, connection)
     161    check_for_migrations(app_config, connection, force=force)
    162162
    163163    output = []
    164164    for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
    def sql_destroy_indexes(app_config, style, connection):  
    177177    return output
    178178
    179179
    180 def sql_all(app_config, style, connection):
     180def sql_all(app_config, style, connection, force=False):
    181181
    182     check_for_migrations(app_config, connection)
     182    check_for_migrations(app_config, connection, force=force)
    183183
    184184    "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
    185185    return (
    186         sql_create(app_config, style, connection) +
    187         sql_custom(app_config, style, connection) +
    188         sql_indexes(app_config, style, connection)
     186        sql_create(app_config, style, connection, force=force) +
     187        sql_custom(app_config, style, connection, force=force) +
     188        sql_indexes(app_config, style, connection, force=force)
    189189    )
    190190
    191191
Back to Top