當前位置: 首頁>>代碼示例>>Python>>正文


Python executor.MigrationExecutor方法代碼示例

本文整理匯總了Python中django.db.migrations.executor.MigrationExecutor方法的典型用法代碼示例。如果您正苦於以下問題:Python executor.MigrationExecutor方法的具體用法?Python executor.MigrationExecutor怎麽用?Python executor.MigrationExecutor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.migrations.executor的用法示例。


在下文中一共展示了executor.MigrationExecutor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: migrations

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def migrations(transactional_db):
    """
    This fixture returns a helper object to test Django data migrations.
    Based on: https://gist.github.com/bennylope/82a6088c02fefdd47e18f3c04ec167af
    """

    class Migrator(object):
        def migrate(self, app, to):
            migration = [(app, to)]
            executor = MigrationExecutor(connection)
            executor.migrate(migration)
            return executor.loader.project_state(migration).apps

        def reset(self):
            call_command("migrate", no_input=True)

    return Migrator() 
開發者ID:mozilla,項目名稱:normandy,代碼行數:19,代碼來源:conftest.py

示例2: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self):
        assert (
            self.migrate_from and self.migrate_to
        ), "TestCase '{}' must define migrate_from and migrate_to properties".format(
            type(self).__name__
        )
        self.migrate_from = [(self.app, self.migrate_from)]
        self.migrate_to = [(self.app, self.migrate_to)]
        executor = MigrationExecutor(connection)
        old_apps = executor.loader.project_state(self.migrate_from).apps

        # Reverse to the original migration
        executor.migrate(self.migrate_from)

        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor = MigrationExecutor(connection)
        executor.loader.build_graph()  # reload.
        executor.migrate(self.migrate_to)

        self.apps = executor.loader.project_state(self.migrate_to).apps 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:24,代碼來源:util.py

示例3: check_migrations

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def check_migrations():
    """
    Check the status of database migrations.
    The koku API server is responsible for running all database migrations.  This method
    will return the state of the database and whether or not all migrations have been completed.
    Hat tip to the Stack Overflow contributor: https://stackoverflow.com/a/31847406
    Returns:
        Boolean - True if database is available and migrations have completed.  False otherwise.
    """
    try:
        connection = connections[DEFAULT_DB_ALIAS]
        connection.prepare_database()
        executor = MigrationExecutor(connection)
        targets = executor.loader.graph.leaf_nodes()
        return not executor.migration_plan(targets)
    except OperationalError:
        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:19,代碼來源:database.py

示例4: check_migrations

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def check_migrations(self):
        """
        Check the status of database migrations.

        The koku API server is responsible for running all database migrations.  This method
        will return the state of the database and whether or not all migrations have been completed.

        Hat tip to the Stack Overflow contributor: https://stackoverflow.com/a/31847406

        Returns:
            Boolean - True if database is available and migrations have completed.  False otherwise.

        """
        connection = connections[DEFAULT_DB_ALIAS]
        connection.prepare_database()
        executor = MigrationExecutor(connection)
        targets = executor.loader.graph.leaf_nodes()
        return not executor.migration_plan(targets) 
開發者ID:project-koku,項目名稱:koku,代碼行數:20,代碼來源:sources.py

示例5: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self):
        assert self.migrate_from and self.migrate_to, \
            "TestCase '{}' must define migrate_from and migrate_to properties".format(type(self).__name__)

        executor = MigrationExecutor(connection)
        old_apps = executor.loader.project_state(self.migrate_from).apps

        # Reverse to the original migration
        executor.migrate(self.migrate_from)

        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor = MigrationExecutor(connection)
        executor.loader.build_graph()  # reload.
        executor.migrate(self.migrate_to)

        self.apps = executor.loader.project_state(self.migrate_to).apps 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:20,代碼來源:utils.py

示例6: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self) -> None:
        assert self.migrate_from and self.migrate_to, \
            f"TestCase '{type(self).__name__}' must define migrate_from and migrate_to properties"
        migrate_from: List[Tuple[str, str]] = [(self.app, self.migrate_from)]
        migrate_to: List[Tuple[str, str]] = [(self.app, self.migrate_to)]
        executor = MigrationExecutor(connection)
        old_apps = executor.loader.project_state(migrate_from).apps

        # Reverse to the original migration
        executor.migrate(migrate_from)

        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor = MigrationExecutor(connection)
        executor.loader.build_graph()  # reload.
        executor.migrate(migrate_to)

        self.apps = executor.loader.project_state(migrate_to).apps 
開發者ID:zulip,項目名稱:zulip,代碼行數:21,代碼來源:test_classes.py

示例7: handle

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def handle(self, *args, **options):
        changed = set()

        self.stdout.write("Checking...")
        for db in settings.DATABASES.keys():
            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                sys.exit("Unable to check migrations: cannot connect to database\n")

            autodetector = MigrationAutodetector(
                executor.loader.project_state(), ProjectState.from_apps(apps),
            )
            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        changed -= set(options["ignore"])

        if changed:
            sys.exit(
                "Apps with model changes but no corresponding migration file: %(changed)s\n"
                % {"changed": list(changed)}
            )
        else:
            sys.stdout.write("All migration files present\n") 
開發者ID:vintasoftware,項目名稱:django-react-boilerplate,代碼行數:26,代碼來源:has_missing_migrations.py

示例8: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self):
        assert (
            self.migrate_from and self.migrate_to
        ), "TestCase '{}' must define migrate_from and migrate_to properties".format(
            type(self).__name__
        )
        self.migrate_from = [(self.app, self.migrate_from)]
        self.migrate_to = [(self.app, self.migrate_to)]
        executor = MigrationExecutor(connection)
        old_apps = executor.loader.project_state(self.migrate_from).apps

        # Reverse to the original migration
        executor.migrate(self.migrate_from)

        if self.migrate_fixtures:
            self.load_fixtures(self.migrate_fixtures, apps=old_apps)

        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor = MigrationExecutor(connection)
        executor.loader.build_graph()  # reload.
        executor.migrate(self.migrate_to)

        self.apps = executor.loader.project_state(self.migrate_to).apps 
開發者ID:byro,項目名稱:byro,代碼行數:27,代碼來源:helper.py

示例9: get_fake_model

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def get_fake_model(fields=None, model_base=LocalizedModel, meta_options={}):
    """Creates a fake model to use during unit tests."""

    model = define_fake_model(fields, model_base, meta_options)

    class TestProject:
        def clone(self, *_args, **_kwargs):
            return self

        @property
        def apps(self):
            return self

    class TestMigration(migrations.Migration):
        operations = [HStoreExtension()]

    with connection.schema_editor() as schema_editor:
        migration_executor = MigrationExecutor(schema_editor.connection)
        migration_executor.apply_migration(
            TestProject(), TestMigration("eh", "postgres_extra")
        )

        schema_editor.create_model(model)

    return model 
開發者ID:SectorLabs,項目名稱:django-localized-fields,代碼行數:27,代碼來源:fake_model.py

示例10: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self):
        self.migrate_from = [self.migrate_from]
        self.migrate_to = [self.migrate_to]

        # Reverse to the original migration
        executor = MigrationExecutor(connection)
        executor.migrate(self.migrate_from)

        old_apps = executor.loader.project_state(self.migrate_from).apps
        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor.loader.build_graph()
        executor.migrate(self.migrate_to)

        self.apps = executor.loader.project_state(self.migrate_to).apps 
開發者ID:SimpleJWT,項目名稱:django-rest-framework-simplejwt,代碼行數:18,代碼來源:utils.py

示例11: test_apply_all_replaced_marks_replacement_as_applied

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def test_apply_all_replaced_marks_replacement_as_applied(self):
        """
        Applying all replaced migrations marks replacement as applied (#24628).
        """
        recorder = MigrationRecorder(connection)
        # Place the database in a state where the replaced migrations are
        # partially applied: 0001 is applied, 0002 is not.
        recorder.record_applied("migrations", "0001_initial")
        executor = MigrationExecutor(connection)
        # Use fake because we don't actually have the first migration
        # applied, so the second will fail. And there's no need to actually
        # create/modify tables here, we're just testing the
        # MigrationRecord, which works the same with or without fake.
        executor.migrate([("migrations", "0002_second")], fake=True)

        # Because we've now applied 0001 and 0002 both, their squashed
        # replacement should be marked as applied.
        self.assertIn(
            ("migrations", "0001_squashed_0002"),
            recorder.applied_migrations(),
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:23,代碼來源:test_executor.py

示例12: test_migrate_marks_replacement_applied_even_if_it_did_nothing

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def test_migrate_marks_replacement_applied_even_if_it_did_nothing(self):
        """
        A new squash migration will be marked as applied even if all its
        replaced migrations were previously already applied (#24628).
        """
        recorder = MigrationRecorder(connection)
        # Record all replaced migrations as applied
        recorder.record_applied("migrations", "0001_initial")
        recorder.record_applied("migrations", "0002_second")
        executor = MigrationExecutor(connection)
        executor.migrate([("migrations", "0001_squashed_0002")])

        # Because 0001 and 0002 are both applied, even though this migrate run
        # didn't apply anything new, their squashed replacement should be
        # marked as applied.
        self.assertIn(
            ("migrations", "0001_squashed_0002"),
            recorder.applied_migrations(),
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:21,代碼來源:test_executor.py

示例13: setUp

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def setUp(self):
        assert self.migrate_from and self.migrate_to, \
            "TestCase '{}' must define migrate_from and migrate_to properties".format(type(self).__name__)
        self.migrate_from = [(self.app, self.migrate_from)]
        self.migrate_to = [(self.app, self.migrate_to)]
        executor = MigrationExecutor(connection)
        old_apps = executor.loader.project_state(self.migrate_from).apps

        # Reverse to the original migration
        executor.migrate(self.migrate_from)

        super(TestMigrations, self).setUp()
        self.setUpBeforeMigration(old_apps)

        # Run the migration to test
        executor = MigrationExecutor(connection)
        executor.loader.build_graph()  # reload.
        executor.migrate(self.migrate_to)

        self.apps = executor.loader.project_state(self.migrate_to).apps 
開發者ID:ResEnv,項目名稱:chain-api,代碼行數:22,代碼來源:test_migrations.py

示例14: test_atomic_operation_in_non_atomic_migration

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def test_atomic_operation_in_non_atomic_migration(self):
        """
        An atomic operation is properly rolled back inside a non-atomic
        migration.
        """
        executor = MigrationExecutor(connection)
        with self.assertRaisesMessage(RuntimeError, "Abort migration"):
            executor.migrate([("migrations", "0001_initial")])
        migrations_apps = executor.loader.project_state(("migrations", "0001_initial")).apps
        Editor = migrations_apps.get_model("migrations", "Editor")
        self.assertFalse(Editor.objects.exists())
        # Record previous migration as successful.
        executor.migrate([("migrations", "0001_initial")], fake=True)
        # Rebuild the graph to reflect the new DB state.
        executor.loader.build_graph()
        # Migrating backwards is also atomic.
        with self.assertRaisesMessage(RuntimeError, "Abort migration"):
            executor.migrate([("migrations", None)])
        self.assertFalse(Editor.objects.exists()) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_executor.py

示例15: test_unrelated_applied_migrations_mutate_state

# 需要導入模塊: from django.db.migrations import executor [as 別名]
# 或者: from django.db.migrations.executor import MigrationExecutor [as 別名]
def test_unrelated_applied_migrations_mutate_state(self):
        """
        #26647 - Unrelated applied migrations should be part of the final
        state in both directions.
        """
        executor = MigrationExecutor(connection)
        executor.migrate([
            ('mutate_state_b', '0002_add_field'),
        ])
        # Migrate forward.
        executor.loader.build_graph()
        state = executor.migrate([
            ('mutate_state_a', '0001_initial'),
        ])
        self.assertIn('added', dict(state.models['mutate_state_b', 'b'].fields))
        executor.loader.build_graph()
        # Migrate backward.
        state = executor.migrate([
            ('mutate_state_a', None),
        ])
        self.assertIn('added', dict(state.models['mutate_state_b', 'b'].fields))
        executor.migrate([
            ('mutate_state_b', None),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:26,代碼來源:test_executor.py


注:本文中的django.db.migrations.executor.MigrationExecutor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。