當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。