Пример #1
0
    def _migrate_from_old_targets(self, tmp_path):
        if "sqlite3" in self.databases['default']['ENGINE']:
            try:
                delete_path(self.databases['default']['NAME'])
            except Exception:
                self.clear(False)
                setup_from_none()
            self.read(True)
        else:
            self.clear(False)

        from django.db import DEFAULT_DB_ALIAS, connections
        from django.apps import apps
        from django.utils.module_loading import module_has_submodule
        from django.db.migrations.executor import MigrationExecutor
        from django.core.management.sql import emit_pre_migrate_signal, emit_post_migrate_signal

        for app_config in apps.get_app_configs():
            if module_has_submodule(app_config.module, "management"):
                import_module('.management', app_config.name)

        connection = connections[DEFAULT_DB_ALIAS]
        connection.prepare_database()
        executor = MigrationExecutor(connection)
        emit_pre_migrate_signal(0, None, connection.alias)
        executor.migrate(executor.loader.graph.leaf_nodes())
        emit_post_migrate_signal(0, None, connection.alias)
        self.clear(True, ['django_migrations'])
Пример #2
0
 def is_database_migrated(self, database=DEFAULT_DB_ALIAS):
     connection = connections[database]
     connection.prepare_database()
     executor = MigrationExecutor(connection)
     targets = executor.loader.graph.leaf_nodes()
     # No plan <=> Yes sync'd
     return not executor.migration_plan(targets)
Пример #3
0
    def _migrate_from_old_targets(self, tmp_path):
        if "sqlite3" in self.databases['default']['ENGINE']:
            try:
                delete_path(self.databases['default']['NAME'])
            except Exception:
                self.clear(False)
                setup_from_none()
            self.read()
        else:
            self.clear(False)

        from django.db import DEFAULT_DB_ALIAS, connections
        from django.apps import apps
        from django.utils.module_loading import module_has_submodule
        from django.db.migrations.executor import MigrationExecutor
        from django.core.management.sql import emit_pre_migrate_signal, emit_post_migrate_signal

        for app_config in apps.get_app_configs():
            if module_has_submodule(app_config.module, "management"):
                import_module('.management', app_config.name)

        connection = connections[DEFAULT_DB_ALIAS]
        connection.prepare_database()
        executor = MigrationExecutor(connection)
        emit_pre_migrate_signal(0, None, connection.alias)
        executor.migrate(executor.loader.graph.leaf_nodes())
        emit_post_migrate_signal(0, None, connection.alias)
        self.clear(True, ['django_migrations'])
Пример #4
0
        def db_sync_unhealthy():
            try:
                connection = connections[DEFAULT_DB_ALIAS]
                connection.prepare_database()
                executor = MigrationExecutor(connection)
                targets = executor.loader.graph.leaf_nodes()
            except:
                return True

            return len(executor.migration_plan(targets)) > 0
Пример #5
0
    def _migrate_from_old_targets(self, tmp_path):
        from django.db import DEFAULT_DB_ALIAS, connections
        from django.apps import apps
        from django.utils.module_loading import module_has_submodule
        from django.db.migrations.executor import MigrationExecutor
        from django.core.management.sql import emit_pre_migrate_signal, emit_post_migrate_signal

        for app_config in apps.get_app_configs():
            if module_has_submodule(app_config.module, "management"):
                import_module('.management', app_config.name)

        connection = connections[DEFAULT_DB_ALIAS]
        connection.prepare_database()
        executor = MigrationExecutor(connection)
        emit_pre_migrate_signal(0, None, connection.alias)
        executor.migrate(executor.loader.graph.leaf_nodes())
        emit_post_migrate_signal(0, None, connection.alias)
        self.clear(True, ['django_migrations'])
Пример #6
0
 def run_new_migration(self, tmp_path):
     from inspect import getmembers, isfunction
     from django.apps import apps
     from django.db import DEFAULT_DB_ALIAS, connections
     from django.db.migrations.executor import MigrationExecutor
     connection = connections[DEFAULT_DB_ALIAS]
     connection.prepare_database()
     executor = MigrationExecutor(connection)
     for target in self.get_other_targets(tmp_path, executor):
         try:
             target_conf = apps.get_app_config(target[0])
             migrat_mod = import_module(
                 "%s.migrations.%s" % (target_conf.module.__name__, target[1]))
             for migr_obj in getmembers(migrat_mod):
                 if isfunction(migr_obj[1]) and (migr_obj[0][0] != '_'):
                     six.print_("run %s.%s.%s" %
                                (target[0], target[1], migr_obj[0]))
                     migr_obj[1]()
         except Exception:
             pass
Пример #7
0
 def run_new_migration(self, tmp_path):
     from inspect import getmembers, isfunction
     from django.apps import apps
     from django.db import DEFAULT_DB_ALIAS, connections
     from django.db.migrations.executor import MigrationExecutor
     connection = connections[DEFAULT_DB_ALIAS]
     connection.prepare_database()
     executor = MigrationExecutor(connection)
     for target in self.get_other_targets(tmp_path, executor):
         try:
             target_conf = apps.get_app_config(target[0])
             migrat_mod = import_module(
                 "%s.migrations.%s" %
                 (target_conf.module.__name__, target[1]))
             for migr_obj in getmembers(migrat_mod):
                 if isfunction(migr_obj[1]) and (migr_obj[0][0] != '_'):
                     six.print_("run %s.%s.%s" %
                                (target[0], target[1], migr_obj[0]))
                     migr_obj[1]()
         except Exception:
             pass