Changed get_migratable_models to use an app config.
This commit is contained in:
parent
1d4bcb86ea
commit
856aaaf2b1
|
@ -94,5 +94,5 @@ Are you sure you want to do this?
|
||||||
# respond as if the database had been migrated from scratch.
|
# respond as if the database had been migrated from scratch.
|
||||||
all_models = []
|
all_models = []
|
||||||
for app_config in apps.get_app_configs(only_with_models_module=True):
|
for app_config in apps.get_app_configs(only_with_models_module=True):
|
||||||
all_models.extend(router.get_migratable_models(app_config.models_module, database, include_auto_created=True))
|
all_models.extend(router.get_migratable_models(app_config, database, include_auto_created=True))
|
||||||
emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
|
emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
|
||||||
|
|
|
@ -180,7 +180,7 @@ class Command(BaseCommand):
|
||||||
# Build the manifest of apps and models that are to be synchronized
|
# Build the manifest of apps and models that are to be synchronized
|
||||||
all_models = [
|
all_models = [
|
||||||
(app_config.label,
|
(app_config.label,
|
||||||
router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True))
|
router.get_migratable_models(app_config, connection.alias, include_auto_created=True))
|
||||||
for app_config in apps.get_app_configs(only_with_models_module=True)
|
for app_config in apps.get_app_configs(only_with_models_module=True)
|
||||||
if app_config.label in app_labels
|
if app_config.label in app_labels
|
||||||
]
|
]
|
||||||
|
|
|
@ -31,7 +31,7 @@ def sql_create(app_config, style, connection):
|
||||||
known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models)
|
known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models)
|
||||||
pending_references = {}
|
pending_references = {}
|
||||||
|
|
||||||
for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
|
for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
|
||||||
output, references = connection.creation.sql_create_model(model, style, known_models)
|
output, references = connection.creation.sql_create_model(model, style, known_models)
|
||||||
final_output.extend(output)
|
final_output.extend(output)
|
||||||
for refto, refs in references.items():
|
for refto, refs in references.items():
|
||||||
|
@ -78,7 +78,7 @@ def sql_delete(app_config, style, connection):
|
||||||
to_delete = set()
|
to_delete = set()
|
||||||
|
|
||||||
references_to_delete = {}
|
references_to_delete = {}
|
||||||
app_models = router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True)
|
app_models = router.get_migratable_models(app_config, connection.alias, include_auto_created=True)
|
||||||
for model in app_models:
|
for model in app_models:
|
||||||
if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
|
if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
|
||||||
# The table exists, so it needs to be dropped
|
# The table exists, so it needs to be dropped
|
||||||
|
@ -122,7 +122,7 @@ def sql_custom(app_config, style, connection):
|
||||||
"Returns a list of the custom table modifying SQL statements for the given app."
|
"Returns a list of the custom table modifying SQL statements for the given app."
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
app_models = router.get_migratable_models(app_config.models_module, connection.alias)
|
app_models = router.get_migratable_models(app_config, connection.alias)
|
||||||
|
|
||||||
for model in app_models:
|
for model in app_models:
|
||||||
output.extend(custom_sql_for_model(model, style, connection))
|
output.extend(custom_sql_for_model(model, style, connection))
|
||||||
|
@ -133,7 +133,7 @@ def sql_custom(app_config, style, connection):
|
||||||
def sql_indexes(app_config, style, connection):
|
def sql_indexes(app_config, style, connection):
|
||||||
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
|
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
|
||||||
output = []
|
output = []
|
||||||
for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
|
for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
|
||||||
output.extend(connection.creation.sql_indexes_for_model(model, style))
|
output.extend(connection.creation.sql_indexes_for_model(model, style))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ def sql_indexes(app_config, style, connection):
|
||||||
def sql_destroy_indexes(app_config, style, connection):
|
def sql_destroy_indexes(app_config, style, connection):
|
||||||
"Returns a list of the DROP INDEX SQL statements for all models in the given app."
|
"Returns a list of the DROP INDEX SQL statements for all models in the given app."
|
||||||
output = []
|
output = []
|
||||||
for model in router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True):
|
for model in router.get_migratable_models(app_config, connection.alias, include_auto_created=True):
|
||||||
output.extend(connection.creation.sql_destroy_indexes_for_model(model, style))
|
output.extend(connection.creation.sql_destroy_indexes_for_model(model, style))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
|
@ -1272,7 +1272,7 @@ class BaseDatabaseIntrospection(object):
|
||||||
from django.db import router
|
from django.db import router
|
||||||
tables = set()
|
tables = set()
|
||||||
for app_config in apps.get_app_configs(only_with_models_module=True):
|
for app_config in apps.get_app_configs(only_with_models_module=True):
|
||||||
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
for model in router.get_migratable_models(app_config, self.connection.alias):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
tables.add(model._meta.db_table)
|
tables.add(model._meta.db_table)
|
||||||
|
@ -1293,7 +1293,7 @@ class BaseDatabaseIntrospection(object):
|
||||||
from django.db import router
|
from django.db import router
|
||||||
all_models = []
|
all_models = []
|
||||||
for app_config in apps.get_app_configs(only_with_models_module=True):
|
for app_config in apps.get_app_configs(only_with_models_module=True):
|
||||||
all_models.extend(router.get_migratable_models(app_config.models_module, self.connection.alias))
|
all_models.extend(router.get_migratable_models(app_config, self.connection.alias))
|
||||||
tables = list(map(self.table_name_converter, tables))
|
tables = list(map(self.table_name_converter, tables))
|
||||||
return set([
|
return set([
|
||||||
m for m in all_models
|
m for m in all_models
|
||||||
|
@ -1308,7 +1308,7 @@ class BaseDatabaseIntrospection(object):
|
||||||
sequence_list = []
|
sequence_list = []
|
||||||
|
|
||||||
for app_config in apps.get_app_configs(only_with_models_module=True):
|
for app_config in apps.get_app_configs(only_with_models_module=True):
|
||||||
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
for model in router.get_migratable_models(app_config, self.connection.alias):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
if model._meta.swapped:
|
if model._meta.swapped:
|
||||||
|
|
|
@ -278,10 +278,9 @@ class ConnectionRouter(object):
|
||||||
return allow
|
return allow
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_migratable_models(self, app, db, include_auto_created=False):
|
def get_migratable_models(self, app_config, db, include_auto_created=False):
|
||||||
"""
|
"""
|
||||||
Return app models allowed to be synchronized on provided db.
|
Return app models allowed to be synchronized on provided db.
|
||||||
"""
|
"""
|
||||||
from django.apps import apps
|
models = app_config.get_models(include_auto_created=include_auto_created)
|
||||||
return [model for model in apps.get_models(app, include_auto_created=include_auto_created)
|
return [model for model in models if self.allow_migrate(db, model)]
|
||||||
if self.allow_migrate(db, model)]
|
|
||||||
|
|
Loading…
Reference in New Issue