diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-10-16 17:58:21 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-10-16 18:02:49 +0200 |
| commit | 650b6fd90efea058c54800d2ba0e0976547894a3 (patch) | |
| tree | 926e672fef2cd90062bac1b84e47f04591c596d7 /django/core | |
| parent | 2992f428614349b0dfe0f4183905f492fd3f62c2 (diff) | |
Add get_migratable_models util method to ConnectionRouter
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/commands/flush.py | 5 | ||||
| -rw-r--r-- | django/core/management/commands/migrate.py | 5 | ||||
| -rw-r--r-- | django/core/management/sql.py | 18 |
3 files changed, 7 insertions, 21 deletions
diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index ea0952cb53..130338a55a 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -94,8 +94,5 @@ Are you sure you want to do this? # respond as if the database had been migrated from scratch. all_models = [] for app in models.get_apps(): - all_models.extend([ - m for m in models.get_models(app, include_auto_created=True) - if router.allow_migrate(database, m) - ]) + all_models.extend(router.get_migratable_models(app, database, include_auto_created=True)) emit_post_migrate_signal(set(all_models), verbosity, interactive, database) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index f351adaaba..14239b1452 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -153,10 +153,7 @@ class Command(BaseCommand): # Build the manifest of apps and models that are to be synchronized all_models = [ (app.__name__.split('.')[-2], - [ - m for m in models.get_models(app, include_auto_created=True) - if router.allow_migrate(connection.alias, m) - ]) + router.get_migratable_models(app, connection.alias, include_auto_created=True)) for app in models.get_apps() if app.__name__.split('.')[-2] in apps ] diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 69772d9fa6..6f60d73ae9 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -10,14 +10,6 @@ from django.core.management.base import CommandError from django.db import models, router -def filtered_app_models(app, db_alias, include_auto_created=False): - """ - Return app models allowed to be synchronized on provided db. - """ - return [model for model in models.get_models(app, include_auto_created=include_auto_created) - if router.allow_migrate(db_alias, model)] - - def sql_create(app, style, connection): "Returns a list of the CREATE TABLE SQL statements for the given app." @@ -38,7 +30,7 @@ def sql_create(app, style, connection): known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models) pending_references = {} - for model in filtered_app_models(app, connection.alias, include_auto_created=True): + for model in router.get_migratable_models(app, connection.alias, include_auto_created=True): output, references = connection.creation.sql_create_model(model, style, known_models) final_output.extend(output) for refto, refs in references.items(): @@ -85,7 +77,7 @@ def sql_delete(app, style, connection): to_delete = set() references_to_delete = {} - app_models = filtered_app_models(app, connection.alias, include_auto_created=True) + app_models = router.get_migratable_models(app, connection.alias, include_auto_created=True) for model in app_models: if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names: # The table exists, so it needs to be dropped @@ -129,7 +121,7 @@ def sql_custom(app, style, connection): "Returns a list of the custom table modifying SQL statements for the given app." output = [] - app_models = filtered_app_models(app, connection.alias) + app_models = router.get_migratable_models(app, connection.alias) for model in app_models: output.extend(custom_sql_for_model(model, style, connection)) @@ -140,7 +132,7 @@ def sql_custom(app, style, connection): def sql_indexes(app, style, connection): "Returns a list of the CREATE INDEX SQL statements for all models in the given app." output = [] - for model in filtered_app_models(app, connection.alias, include_auto_created=True): + for model in router.get_migratable_models(app, connection.alias, include_auto_created=True): output.extend(connection.creation.sql_indexes_for_model(model, style)) return output @@ -148,7 +140,7 @@ def sql_indexes(app, style, connection): def sql_destroy_indexes(app, style, connection): "Returns a list of the DROP INDEX SQL statements for all models in the given app." output = [] - for model in filtered_app_models(app, connection.alias, include_auto_created=True): + for model in router.get_migratable_models(app, connection.alias, include_auto_created=True): output.extend(connection.creation.sql_destroy_indexes_for_model(model, style)) return output |
