Commit 856aaaf2 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Changed get_migratable_models to use an app config.

parent 1d4bcb86
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -94,5 +94,5 @@ Are you sure you want to do this?
        # respond as if the database had been migrated from scratch.
        all_models = []
        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)
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ class Command(BaseCommand):
        # Build the manifest of apps and models that are to be synchronized
        all_models = [
            (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)
            if app_config.label in app_labels
        ]
+5 −5
Original line number Diff line number Diff line
@@ -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)
    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)
        final_output.extend(output)
        for refto, refs in references.items():
@@ -78,7 +78,7 @@ def sql_delete(app_config, style, connection):
    to_delete = set()

    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:
        if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
            # 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."
    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:
        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):
    "Returns a list of the CREATE INDEX SQL statements for all models in the given app."
    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))
    return output

@@ -141,7 +141,7 @@ def sql_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."
    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))
    return output

+3 −3
Original line number Diff line number Diff line
@@ -1272,7 +1272,7 @@ class BaseDatabaseIntrospection(object):
        from django.db import router
        tables = set()
        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:
                    continue
                tables.add(model._meta.db_table)
@@ -1293,7 +1293,7 @@ class BaseDatabaseIntrospection(object):
        from django.db import router
        all_models = []
        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))
        return set([
            m for m in all_models
@@ -1308,7 +1308,7 @@ class BaseDatabaseIntrospection(object):
        sequence_list = []

        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:
                    continue
                if model._meta.swapped:
+3 −4
Original line number Diff line number Diff line
@@ -278,10 +278,9 @@ class ConnectionRouter(object):
                    return allow
        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.
        """
        from django.apps import apps
        return [model for model in apps.get_models(app, include_auto_created=include_auto_created)
                if self.allow_migrate(db, model)]
        models = app_config.get_models(include_auto_created=include_auto_created)
        return [model for model in models if self.allow_migrate(db, model)]