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


Python autodetector.MigrationAutodetector方法代码示例

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


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

示例1: test_total_deconstruct

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_total_deconstruct(self):
        loader = MigrationLoader(None, load=True, ignore_no_migrations=True)
        loader.disk_migrations = {t: v for t, v in loader.disk_migrations.items() if t[0] != 'testapp'}
        app_labels = {"testapp"}
        questioner = NonInteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=True)
        autodetector = MigrationAutodetector(
            loader.project_state(),
            ProjectState.from_apps(apps),
            questioner,
        )
        # Detect changes
        changes = autodetector.changes(
            graph=loader.graph,
            trim_to_apps=app_labels or None,
            convert_apps=app_labels or None,
            migration_name="my_fake_migration_for_test_deconstruct",
        )
        self.assertGreater(len(changes), 0)
        for app_label, app_migrations in changes.items():
            for migration in app_migrations:
                # Describe the migration
                writer = MigrationWriter(migration)

                migration_string = writer.as_string()
                self.assertNotEqual(migration_string, "") 
开发者ID:onysos,项目名称:django-composite-foreignkey,代码行数:27,代码来源:tests.py

示例2: handle

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

示例3: test_arrange_for_graph

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_arrange_for_graph(self):
        """Tests auto-naming of migrations for graph matching."""
        # Make a fake graph
        graph = MigrationGraph()
        graph.add_node(("testapp", "0001_initial"), None)
        graph.add_node(("testapp", "0002_foobar"), None)
        graph.add_node(("otherapp", "0001_initial"), None)
        graph.add_dependency("testapp.0002_foobar", ("testapp", "0002_foobar"), ("testapp", "0001_initial"))
        graph.add_dependency("testapp.0002_foobar", ("testapp", "0002_foobar"), ("otherapp", "0001_initial"))
        # Use project state to make a new migration change set
        before = self.make_project_state([])
        after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable])
        autodetector = MigrationAutodetector(before, after)
        changes = autodetector._detect_changes()
        # Run through arrange_for_graph
        changes = autodetector.arrange_for_graph(changes, graph)
        # Make sure there's a new name, deps match, etc.
        self.assertEqual(changes["testapp"][0].name, "0003_author")
        self.assertEqual(changes["testapp"][0].dependencies, [("testapp", "0002_foobar")])
        self.assertEqual(changes["otherapp"][0].name, "0002_pony_stable")
        self.assertEqual(changes["otherapp"][0].dependencies, [("otherapp", "0001_initial")]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:23,代码来源:test_autodetector.py

示例4: test_trim_apps

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_trim_apps(self):
        """
        Trim does not remove dependencies but does remove unwanted apps.
        """
        # Use project state to make a new migration change set
        before = self.make_project_state([])
        after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable, self.third_thing])
        autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_initial": True}))
        changes = autodetector._detect_changes()
        # Run through arrange_for_graph
        graph = MigrationGraph()
        changes = autodetector.arrange_for_graph(changes, graph)
        changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
        changes = autodetector._trim_to_apps(changes, {"testapp"})
        # Make sure there's the right set of migrations
        self.assertEqual(changes["testapp"][0].name, "0001_initial")
        self.assertEqual(changes["otherapp"][0].name, "0001_initial")
        self.assertNotIn("thirdapp", changes) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_autodetector.py

示例5: test_custom_migration_name

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_custom_migration_name(self):
        """Tests custom naming of migrations for graph matching."""
        # Make a fake graph
        graph = MigrationGraph()
        graph.add_node(("testapp", "0001_initial"), None)
        graph.add_node(("testapp", "0002_foobar"), None)
        graph.add_node(("otherapp", "0001_initial"), None)
        graph.add_dependency("testapp.0002_foobar", ("testapp", "0002_foobar"), ("testapp", "0001_initial"))

        # Use project state to make a new migration change set
        before = self.make_project_state([])
        after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable])
        autodetector = MigrationAutodetector(before, after)
        changes = autodetector._detect_changes()

        # Run through arrange_for_graph
        migration_name = 'custom_name'
        changes = autodetector.arrange_for_graph(changes, graph, migration_name)

        # Make sure there's a new name, deps match, etc.
        self.assertEqual(changes["testapp"][0].name, "0003_%s" % migration_name)
        self.assertEqual(changes["testapp"][0].dependencies, [("testapp", "0002_foobar")])
        self.assertEqual(changes["otherapp"][0].name, "0002_%s" % migration_name)
        self.assertEqual(changes["otherapp"][0].dependencies, [("otherapp", "0001_initial")]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:test_autodetector.py

示例6: test_swappable_changed

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_swappable_changed(self):
        with isolate_lru_cache(apps.get_swappable_settings_name):
            before = self.make_project_state([self.custom_user, self.author_with_user])
            with override_settings(AUTH_USER_MODEL="thirdapp.CustomUser"):
                after = self.make_project_state([self.custom_user, self.author_with_custom_user])
            autodetector = MigrationAutodetector(before, after)
            changes = autodetector._detect_changes()
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, model_name="author", name='user')
        fk_field = changes['testapp'][0].operations[0].field
        to_model = '%s.%s' % (
            fk_field.remote_field.model._meta.app_label,
            fk_field.remote_field.model._meta.object_name,
        )
        self.assertEqual(to_model, 'thirdapp.CustomUser') 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:19,代码来源:test_autodetector.py

示例7: test_last_dependency

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_last_dependency(self):
        """
        A dependency to an app with existing migrations uses the
        last migration of that app.
        """
        # Load graph
        loader = MigrationLoader(connection)
        before = self.make_project_state([])
        after = self.make_project_state([self.book_migrations_fk])
        after.real_apps = ["migrations"]
        autodetector = MigrationAutodetector(before, after)
        changes = autodetector._detect_changes(graph=loader.graph)
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'otherapp', 1)
        self.assertOperationTypes(changes, 'otherapp', 0, ["CreateModel"])
        self.assertOperationAttributes(changes, 'otherapp', 0, 0, name="Book")
        self.assertMigrationDependencies(changes, 'otherapp', 0, [("migrations", "0002_second")]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:19,代码来源:test_autodetector.py

示例8: test_first_dependency

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_first_dependency(self):
        """
        A dependency to an app with no migrations uses __first__.
        """
        # Load graph
        loader = MigrationLoader(connection)
        before = self.make_project_state([])
        after = self.make_project_state([self.book_migrations_fk])
        after.real_apps = ["migrations"]
        autodetector = MigrationAutodetector(before, after)
        changes = autodetector._detect_changes(graph=loader.graph)
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'otherapp', 1)
        self.assertOperationTypes(changes, 'otherapp', 0, ["CreateModel"])
        self.assertOperationAttributes(changes, 'otherapp', 0, 0, name="Book")
        self.assertMigrationDependencies(changes, 'otherapp', 0, [("migrations", "__first__")]) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_autodetector.py

示例9: run

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def run(self, *args, **kwargs):

        changed = set()

        log.info("Checking DB migrations")
        for db in settings.DATABASES.keys():

            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                log.critical("Unable to check migrations, cannot connect to database")
                sys.exit(1)

            autodetector = MigrationAutodetector(
                executor.loader.project_state(), ProjectState.from_apps(apps)
            )

            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        if changed:
            log.critical(
                "Apps with model changes but no corresponding "
                f"migration file: {list(changed)}"
            )
            sys.exit(1)
        else:
            log.info("All migration files present") 
开发者ID:webkom,项目名称:lego,代码行数:29,代码来源:missing_migrations.py

示例10: test_for_missing_migrations

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_for_missing_migrations(self):
        """Checks if there're models changes which aren't reflected in migrations."""
        migrations_loader = MigrationExecutor(connection).loader
        migrations_detector = MigrationAutodetector(
            from_state=migrations_loader.project_state(),
            to_state=ProjectState.from_apps(apps)
        )
        if migrations_detector.changes(graph=migrations_loader.graph):
            self.fail(
                'Your models have changes that are not yet reflected '
                'in a migration. You should add them now.'
            ) 
开发者ID:yunojuno-archive,项目名称:django-package-monitor,代码行数:14,代码来源:test_migrations.py

示例11: test__migrations

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test__migrations(self):
        app_labels = set(app.label for app in apps.get_app_configs()
                         if app.name.startswith('wagtail.'))
        for app_label in app_labels:
            apps.get_app_config(app_label.split('.')[-1])
        loader = MigrationLoader(None, ignore_no_migrations=True)

        conflicts = dict(
            (app_label, conflict)
            for app_label, conflict in loader.detect_conflicts().items()
            if app_label in app_labels
        )

        if conflicts:
            name_str = "; ".join("%s in %s" % (", ".join(names), app)
                                 for app, names in conflicts.items())
            self.fail("Conflicting migrations detected (%s)." % name_str)

        autodetector = MigrationAutodetector(
            loader.project_state(),
            ProjectState.from_apps(apps),
            MigrationQuestioner(specified_apps=app_labels, dry_run=True),
        )

        changes = autodetector.changes(
            graph=loader.graph,
            trim_to_apps=app_labels or None,
            convert_apps=app_labels or None,
        )

        if changes:
            migrations = '\n'.join((
                '  {migration}\n{changes}'.format(
                    migration=migration,
                    changes='\n'.join('    {0}'.format(operation.describe())
                                      for operation in migration.operations))
                for (_, migrations) in changes.items()
                for migration in migrations))

            self.fail('Model changes with no migrations detected:\n%s' % migrations) 
开发者ID:wagtail,项目名称:wagtail,代码行数:42,代码来源:test_migrations.py

示例12: test_for_missing_migrations

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_for_missing_migrations(self):
        """Checks if there're models changes which aren't reflected in migrations."""
        migrations_loader = MigrationExecutor(connection).loader
        migrations_detector = MigrationAutodetector(
            from_state=migrations_loader.project_state(),
            to_state=ProjectState.from_apps(apps),
        )
        if migrations_detector.changes(graph=migrations_loader.graph):
            self.fail(
                "Your models have changes that are not yet reflected "
                "in a migration. You should add them now."
            ) 
开发者ID:yunojuno,项目名称:django-request-profiler,代码行数:14,代码来源:test_middleware.py

示例13: handle

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def handle(self, *args, **kwargs):

        changed = set()
        ignore_list = ['authtools']  # dependencies that we don't care about migrations for (usually for testing only)

        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())

        for ignore in ignore_list:
            if ignore in changed:
                changed.remove(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:WimpyAnalytics,项目名称:django-andablog,代码行数:32,代码来源:check_missing_migrations.py

示例14: test_for_missing_migrations

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def test_for_missing_migrations(self):
        """Checks if there're models changes which aren't reflected in migrations."""
        current_models_state = ProjectState.from_apps(apps)
        # skip tracking changes for TestModel
        current_models_state.remove_model("tests", "testmodel")

        migrations_loader = MigrationExecutor(connection).loader
        migrations_detector = MigrationAutodetector(
            from_state=migrations_loader.project_state(), to_state=current_models_state
        )
        if migrations_detector.changes(graph=migrations_loader.graph):
            self.fail(
                "Your models have changes that are not yet reflected "
                "in a migration. You should add them now."
            ) 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:17,代码来源:test_migrations.py

示例15: get_changes

# 需要导入模块: from django.db.migrations import autodetector [as 别名]
# 或者: from django.db.migrations.autodetector import MigrationAutodetector [as 别名]
def get_changes(self, before_states, after_states, questioner=None):
        return MigrationAutodetector(
            self.make_project_state(before_states),
            self.make_project_state(after_states),
            questioner,
        )._detect_changes() 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:8,代码来源:test_autodetector.py


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