当前位置: 首页>>代码示例>>Python>>正文


Python recorder.MigrationRecorder方法代码示例

本文整理汇总了Python中django.db.migrations.recorder.MigrationRecorder方法的典型用法代码示例。如果您正苦于以下问题:Python recorder.MigrationRecorder方法的具体用法?Python recorder.MigrationRecorder怎么用?Python recorder.MigrationRecorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.migrations.recorder的用法示例。


在下文中一共展示了recorder.MigrationRecorder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_consistent_history

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def check_consistent_history(self, connection):
        """
        Raise InconsistentMigrationHistory if any applied migrations have
        unapplied dependencies.
        """
        recorder = MigrationRecorder(connection)
        applied = recorder.applied_migrations()
        for migration in applied:
            # If the migration is unknown, skip it.
            if migration not in self.graph.nodes:
                continue
            for parent in self.graph.node_map[migration].parents:
                if parent not in applied:
                    # Skip unapplied squashed migrations that have all of their
                    # `replaces` applied.
                    if parent in self.replacements:
                        if all(m in applied for m in self.replacements[parent].replaces):
                            continue
                    raise InconsistentMigrationHistory(
                        "Migration {}.{} is applied before its dependency "
                        "{}.{} on database '{}'.".format(
                            migration[0], migration[1], parent[0], parent[1],
                            connection.alias,
                        )
                    ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:loader.py

示例2: test_migrate_record_replaced

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_migrate_record_replaced(self):
        """
        Running a single squashed migration should record all of the original
        replaced migrations as run.
        """
        recorder = MigrationRecorder(connection)
        out = six.StringIO()
        call_command("migrate", "migrations", verbosity=0)
        call_command("showmigrations", "migrations", stdout=out, no_color=True)
        self.assertEqual(
            'migrations\n'
            ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
            out.getvalue().lower()
        )
        applied_migrations = recorder.applied_migrations()
        self.assertIn(("migrations", "0001_initial"), applied_migrations)
        self.assertIn(("migrations", "0002_second"), applied_migrations)
        self.assertIn(("migrations", "0001_squashed_0002"), applied_migrations)
        # Rollback changes
        call_command("migrate", "migrations", "zero", verbosity=0) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:22,代码来源:test_commands.py

示例3: test_migrate_record_squashed

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_migrate_record_squashed(self):
        """
        Running migrate for a squashed migration should record as run
        if all of the replaced migrations have been run (#25231).
        """
        recorder = MigrationRecorder(connection)
        recorder.record_applied("migrations", "0001_initial")
        recorder.record_applied("migrations", "0002_second")
        out = six.StringIO()
        call_command("migrate", "migrations", verbosity=0)
        call_command("showmigrations", "migrations", stdout=out, no_color=True)
        self.assertEqual(
            'migrations\n'
            ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
            out.getvalue().lower()
        )
        self.assertIn(
            ("migrations", "0001_squashed_0002"),
            recorder.applied_migrations()
        )
        # No changes were actually applied so there is nothing to rollback 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:23,代码来源:test_commands.py

示例4: test_apply

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_apply(self):
        """
        Tests marking migrations as applied/unapplied.
        """
        recorder = MigrationRecorder(connection)
        self.assertEqual(
            set((x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"),
            set(),
        )
        recorder.record_applied("myapp", "0432_ponies")
        self.assertEqual(
            set((x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"),
            {("myapp", "0432_ponies")},
        )
        # That should not affect records of another database
        recorder_other = MigrationRecorder(connections['other'])
        self.assertEqual(
            set((x, y) for (x, y) in recorder_other.applied_migrations() if x == "myapp"),
            set(),
        )
        recorder.record_unapplied("myapp", "0432_ponies")
        self.assertEqual(
            set((x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"),
            set(),
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:27,代码来源:test_loader.py

示例5: test_loading_squashed

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_loading_squashed(self):
        "Tests loading a squashed migration"
        migration_loader = MigrationLoader(connection)
        recorder = MigrationRecorder(connection)
        self.addCleanup(recorder.flush)
        # Loading with nothing applied should just give us the one node
        self.assertEqual(
            len([x for x in migration_loader.graph.nodes if x[0] == "migrations"]),
            1,
        )
        # However, fake-apply one migration and it should now use the old two
        recorder.record_applied("migrations", "0001_initial")
        migration_loader.build_graph()
        self.assertEqual(
            len([x for x in migration_loader.graph.nodes if x[0] == "migrations"]),
            2,
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:19,代码来源:test_loader.py

示例6: test_loading_squashed_complex_multi_apps_partially_applied

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_loading_squashed_complex_multi_apps_partially_applied(self):
        loader = MigrationLoader(connection)
        recorder = MigrationRecorder(connection)
        recorder.record_applied('app1', '1_auto')
        recorder.record_applied('app1', '2_auto')
        loader.build_graph()

        plan = set(loader.graph.forwards_plan(('app1', '4_auto')))
        plan = plan - loader.applied_migrations
        expected_plan = {
            ('app2', '1_squashed_2'),
            ('app1', '3_auto'),
            ('app1', '4_auto'),
        }

        self.assertEqual(plan, expected_plan) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:18,代码来源:test_loader.py

示例7: test_apply_all_replaced_marks_replacement_as_applied

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [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

示例8: test_migrate_marks_replacement_applied_even_if_it_did_nothing

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [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

示例9: test_migrate_record_replaced

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_migrate_record_replaced(self):
        """
        Running a single squashed migration should record all of the original
        replaced migrations as run.
        """
        recorder = MigrationRecorder(connection)
        out = io.StringIO()
        call_command("migrate", "migrations", verbosity=0)
        call_command("showmigrations", "migrations", stdout=out, no_color=True)
        self.assertEqual(
            'migrations\n'
            ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
            out.getvalue().lower()
        )
        applied_migrations = recorder.applied_migrations()
        self.assertIn(("migrations", "0001_initial"), applied_migrations)
        self.assertIn(("migrations", "0002_second"), applied_migrations)
        self.assertIn(("migrations", "0001_squashed_0002"), applied_migrations)
        # Rollback changes
        call_command("migrate", "migrations", "zero", verbosity=0) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_commands.py

示例10: test_migrate_record_squashed

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_migrate_record_squashed(self):
        """
        Running migrate for a squashed migration should record as run
        if all of the replaced migrations have been run (#25231).
        """
        recorder = MigrationRecorder(connection)
        recorder.record_applied("migrations", "0001_initial")
        recorder.record_applied("migrations", "0002_second")
        out = io.StringIO()
        call_command("migrate", "migrations", verbosity=0)
        call_command("showmigrations", "migrations", stdout=out, no_color=True)
        self.assertEqual(
            'migrations\n'
            ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
            out.getvalue().lower()
        )
        self.assertIn(
            ("migrations", "0001_squashed_0002"),
            recorder.applied_migrations()
        )
        # No changes were actually applied so there is nothing to rollback 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:test_commands.py

示例11: test_apply

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_apply(self):
        """
        Tests marking migrations as applied/unapplied.
        """
        recorder = MigrationRecorder(connection)
        self.assertEqual(
            {(x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"},
            set(),
        )
        recorder.record_applied("myapp", "0432_ponies")
        self.assertEqual(
            {(x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"},
            {("myapp", "0432_ponies")},
        )
        # That should not affect records of another database
        recorder_other = MigrationRecorder(connections['other'])
        self.assertEqual(
            {(x, y) for (x, y) in recorder_other.applied_migrations() if x == "myapp"},
            set(),
        )
        recorder.record_unapplied("myapp", "0432_ponies")
        self.assertEqual(
            {(x, y) for (x, y) in recorder.applied_migrations() if x == "myapp"},
            set(),
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:test_loader.py

示例12: test_migrate_marks_replacement_applied_even_if_it_did_nothing

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [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(),
        )

    # When the feature is False, the operation and the record won't be
    # performed in a transaction and the test will systematically pass. 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:test_executor.py

示例13: tearDown

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def tearDown(self):
        # Reset applied-migrations state.
        for db in connections:
            recorder = MigrationRecorder(connections[db])
            recorder.migration_qs.filter(app='migrations').delete() 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:7,代码来源:test_base.py

示例14: test_migrate_inconsistent_history

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_migrate_inconsistent_history(self):
        """
        Running migrate with some migrations applied before their dependencies
        should not be allowed.
        """
        recorder = MigrationRecorder(connection)
        recorder.record_applied("migrations", "0002_second")
        msg = "Migration migrations.0002_second is applied before its dependency migrations.0001_initial"
        with self.assertRaisesMessage(InconsistentMigrationHistory, msg):
            call_command("migrate")
        applied_migrations = recorder.applied_migrations()
        self.assertNotIn(("migrations", "0001_initial"), applied_migrations) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:14,代码来源:test_commands.py

示例15: test_check_consistent_history_squashed

# 需要导入模块: from django.db.migrations import recorder [as 别名]
# 或者: from django.db.migrations.recorder import MigrationRecorder [as 别名]
def test_check_consistent_history_squashed(self):
        """
        MigrationLoader.check_consistent_history() should ignore unapplied
        squashed migrations that have all of their `replaces` applied.
        """
        loader = MigrationLoader(connection=None)
        recorder = MigrationRecorder(connection)
        recorder.record_applied('migrations', '0001_initial')
        recorder.record_applied('migrations', '0002_second')
        loader.check_consistent_history(connection)
        recorder.record_applied('migrations', '0003_third')
        loader.check_consistent_history(connection) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:14,代码来源:test_loader.py


注:本文中的django.db.migrations.recorder.MigrationRecorder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。