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


Python state.ProjectState方法代码示例

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


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

示例1: make_state

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def make_state(self, nodes=None, at_end=True, real_apps=None):
        """
        Given a migration node or nodes, returns a complete ProjectState for it.
        If at_end is False, returns the state before the migration has run.
        If nodes is not provided, returns the overall most current project state.
        """
        if nodes is None:
            nodes = list(self.leaf_nodes())
        if len(nodes) == 0:
            return ProjectState()
        if not isinstance(nodes[0], tuple):
            nodes = [nodes]
        plan = []
        for node in nodes:
            for migration in self.forwards_plan(node):
                if migration not in plan:
                    if not at_end and migration in nodes:
                        continue
                    plan.append(migration)
        project_state = ProjectState(real_apps=real_apps)
        for node in plan:
            project_state = self.nodes[node].mutate_state(project_state, preserve=False)
        return project_state 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:graph.py

示例2: apply_initial_migration

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def apply_initial_migration(self, targets: MigrationSpec) -> ProjectState:
        """Reverse back to the original migration."""
        targets = normalize(targets)

        style = no_style()
        # start from clean database state
        sql.drop_models_tables(self._database, style)
        sql.flush_django_migrations_table(self._database, style)

        # prepare as broad plan as possible based on full plan
        self._executor.loader.build_graph()  # reload
        full_plan = self._executor.migration_plan(
            self._executor.loader.graph.leaf_nodes(),
            clean_start=True,
        )
        plan = truncate_plan(targets, full_plan)

        # apply all migrations from generated plan on clean database
        # (only forward, so any unexpected migration won't be applied)
        # to restore database state before tested migration
        return self._migrate(targets, plan=plan) 
开发者ID:wemake-services,项目名称:django-test-migrations,代码行数:23,代码来源:migrator.py

示例3: make_state

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def make_state(self, nodes=None, at_end=True, real_apps=None):
        """
        Given a migration node or nodes, return a complete ProjectState for it.
        If at_end is False, return the state before the migration has run.
        If nodes is not provided, return the overall most current project state.
        """
        if nodes is None:
            nodes = list(self.leaf_nodes())
        if len(nodes) == 0:
            return ProjectState()
        if not isinstance(nodes[0], tuple):
            nodes = [nodes]
        plan = []
        for node in nodes:
            for migration in self.forwards_plan(node):
                if migration not in plan:
                    if not at_end and migration in nodes:
                        continue
                    plan.append(migration)
        project_state = ProjectState(real_apps=real_apps)
        for node in plan:
            project_state = self.nodes[node].mutate_state(project_state, preserve=False)
        return project_state 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:graph.py

示例4: make_state

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def make_state(self, nodes=None, at_end=True, real_apps=None):
        """
        Given a migration node or nodes, return a complete ProjectState for it.
        If at_end is False, return the state before the migration has run.
        If nodes is not provided, return the overall most current project state.
        """
        if nodes is None:
            nodes = list(self.leaf_nodes())
        if not nodes:
            return ProjectState()
        if not isinstance(nodes[0], tuple):
            nodes = [nodes]
        plan = self._generate_plan(nodes, at_end)
        project_state = ProjectState(real_apps=real_apps)
        for node in plan:
            project_state = self.nodes[node].mutate_state(project_state, preserve=False)
        return project_state 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:19,代码来源:graph.py

示例5: test_install_plugin

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def test_install_plugin(self):
        """
        Test we can load the example plugin that every version of MySQL ships
        with.
        """
        assert not plugin_exists("metadata_lock_info")

        state = ProjectState()
        operation = InstallPlugin("metadata_lock_info", "metadata_lock_info.so")
        assert (
            operation.describe()
            == "Installs plugin metadata_lock_info from metadata_lock_info.so"
        )
        new_state = state.clone()
        with connection.schema_editor() as editor:
            operation.database_forwards("testapp", editor, state, new_state)

        assert plugin_exists("metadata_lock_info")

        new_state = state.clone()
        with connection.schema_editor() as editor:
            operation.database_backwards("testapp", editor, new_state, state)

        assert not plugin_exists("metadata_lock_info") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:26,代码来源:test_operations.py

示例6: test_install_soname

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def test_install_soname(self):
        """
        Test we can load the 'metadata_lock_info' library.
        """
        assert not plugin_exists("metadata_lock_info")

        state = ProjectState()
        operation = InstallSOName("metadata_lock_info.so")
        assert operation.describe() == "Installs library metadata_lock_info.so"

        new_state = state.clone()
        with connection.schema_editor() as editor:
            operation.database_forwards("testapp", editor, state, new_state)
        assert plugin_exists("metadata_lock_info")

        new_state = state.clone()
        with connection.schema_editor() as editor:
            operation.database_backwards("testapp", editor, new_state, state)
        assert not plugin_exists("metadata_lock_info") 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:21,代码来源:test_operations.py

示例7: _test_create_model

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def _test_create_model(self, app_label, should_run):
        """
        CreateModel honors multi-db settings.
        """
        operation = migrations.CreateModel(
            "Pony",
            [("id", models.AutoField(primary_key=True))],
        )
        # Test the state alteration
        project_state = ProjectState()
        new_state = project_state.clone()
        operation.state_forwards(app_label, new_state)
        # Test the database alteration
        self.assertTableNotExists("%s_pony" % app_label)
        with connection.schema_editor() as editor:
            operation.database_forwards(app_label, editor, project_state, new_state)
        if should_run:
            self.assertTableExists("%s_pony" % app_label)
        else:
            self.assertTableNotExists("%s_pony" % app_label)
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards(app_label, editor, new_state, project_state)
        self.assertTableNotExists("%s_pony" % app_label) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:test_multidb.py

示例8: test_rename_model_state_forwards

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def test_rename_model_state_forwards(self):
        """
        RenameModel operations shouldn't trigger the caching of rendered apps
        on state without prior apps.
        """
        state = ProjectState()
        state.add_model(ModelState('migrations', 'Foo', []))
        operation = migrations.RenameModel('Foo', 'Bar')
        operation.state_forwards('migrations', state)
        self.assertNotIn('apps', state.__dict__)
        self.assertNotIn(('migrations', 'foo'), state.models)
        self.assertIn(('migrations', 'bar'), state.models)
        # Now with apps cached.
        apps = state.apps
        operation = migrations.RenameModel('Bar', 'Foo')
        operation.state_forwards('migrations', state)
        self.assertIs(state.apps, apps)
        self.assertNotIn(('migrations', 'bar'), state.models)
        self.assertIn(('migrations', 'foo'), state.models) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:21,代码来源:test_operations.py

示例9: test_alter_field_reloads_state_on_fk_target_changes

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def test_alter_field_reloads_state_on_fk_target_changes(self):
        """
        If AlterField doesn't reload state appropriately, the second AlterField
        crashes on MySQL due to not dropping the PonyRider.pony foreign key
        constraint before modifying the column.
        """
        app_label = 'alter_alter_field_reloads_state_on_fk_target_changes'
        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel('Rider', fields=[
                ('id', models.CharField(primary_key=True, max_length=100)),
            ]),
            migrations.CreateModel('Pony', fields=[
                ('id', models.CharField(primary_key=True, max_length=100)),
                ('rider', models.ForeignKey('%s.Rider' % app_label, models.CASCADE)),
            ]),
            migrations.CreateModel('PonyRider', fields=[
                ('id', models.AutoField(primary_key=True)),
                ('pony', models.ForeignKey('%s.Pony' % app_label, models.CASCADE)),
            ]),
        ])
        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.AlterField('Rider', 'id', models.CharField(primary_key=True, max_length=99)),
            migrations.AlterField('Pony', 'id', models.CharField(primary_key=True, max_length=99)),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_operations.py

示例10: test_rename_field_reloads_state_on_fk_target_changes

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def test_rename_field_reloads_state_on_fk_target_changes(self):
        """
        If RenameField doesn't reload state appropriately, the AlterField
        crashes on MySQL due to not dropping the PonyRider.pony foreign key
        constraint before modifying the column.
        """
        app_label = 'alter_rename_field_reloads_state_on_fk_target_changes'
        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel('Rider', fields=[
                ('id', models.CharField(primary_key=True, max_length=100)),
            ]),
            migrations.CreateModel('Pony', fields=[
                ('id', models.CharField(primary_key=True, max_length=100)),
                ('rider', models.ForeignKey('%s.Rider' % app_label, models.CASCADE)),
            ]),
            migrations.CreateModel('PonyRider', fields=[
                ('id', models.AutoField(primary_key=True)),
                ('pony', models.ForeignKey('%s.Pony' % app_label, models.CASCADE)),
            ]),
        ])
        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameField('Rider', 'id', 'id2'),
            migrations.AlterField('Pony', 'id', models.CharField(primary_key=True, max_length=99)),
        ], atomic=connection.features.supports_atomic_references_rename) 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_operations.py

示例11: patch_enum

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def patch_enum():
    """ Applies the patches necessary for django_enum to work """
    # Patch migrations classes
    logger.info('Applying django_enum patches')

    # If no support for add_type, apply django_types to add it
    from django.db.migrations.state import ProjectState
    if not hasattr(ProjectState, 'add_type'):
        from django_types import patch_types
        patch_types()

    with patchy('django.db.migrations', 'django_enum.patches') as p:
        p.cls('questioner.MigrationQuestioner').auto()
        p.cls('questioner.InteractiveMigrationQuestioner').auto()
        p.cls('autodetector.MigrationAutodetector').auto()

    # Patch backend features
    with patchy('django.db.backends', 'django_enum.patches') as p:
        # Add base changes necessary
        p.cls('base.features.BaseDatabaseFeatures').auto()

        # Only patch database backends in use (avoid dependencies)
        for backend in set(db_dict['ENGINE'] for db_name, db_dict in settings.DATABASES.items()):
            if backend == 'django.db.backends.postgresql':
                import django.db.backends.postgresql.base
                p.cls('postgresql.features.DatabaseFeatures', 'PostgresDatabaseFeatures').auto()
                p.cls('postgresql.schema.DatabaseSchemaEditor', 'PostgresDatabaseSchemaEditor').auto()
            if backend == 'django.db.backends.mysql':
                import django.db.backends.mysql.base
                p.cls('mysql.features.DatabaseFeatures', 'MysqlDatabaseFeatures').auto() 
开发者ID:ashleywaite,项目名称:django-more,代码行数:32,代码来源:__init__.py

示例12: ready

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def ready(self):
        # If no support for add_type, apply django_types to add it
        from django.db.migrations.state import ProjectState
        if not hasattr(ProjectState, 'add_type'):
            from django_types import patch_types
            patch_types() 
开发者ID:ashleywaite,项目名称:django-more,代码行数:8,代码来源:apps.py

示例13: database_forwards

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def database_forwards(self, app_label, schema_editor: BaseDatabaseSchemaEditor, from_state, to_state: ProjectState):
        to_model = to_state.apps.get_model(app_label, self.model_name)
        meta = to_model._meta
        to_field = meta.get_field(self.name)
        if to_field.default != NOT_PROVIDED:
            table_name = schema_editor.quote_name(meta.db_table)
            column = schema_editor.quote_name(to_field.column)
            default = schema_editor.quote_value(to_field.default)
            schema_editor.execute("ALTER TABLE {} ALTER COLUMN {} SET DEFAULT {}".format(table_name, column, default)) 
开发者ID:zaihui,项目名称:hutils,代码行数:11,代码来源:migrations.py

示例14: apply_tested_migration

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def apply_tested_migration(self, targets: MigrationSpec) -> ProjectState:
        """Apply the next migration."""
        self._executor.loader.build_graph()  # reload
        return self._migrate(normalize(targets)) 
开发者ID:wemake-services,项目名称:django-test-migrations,代码行数:6,代码来源:migrator.py

示例15: _migrate

# 需要导入模块: from django.db.migrations import state [as 别名]
# 或者: from django.db.migrations.state import ProjectState [as 别名]
def _migrate(
        self,
        migration_targets: MigrationSpec,
        plan: Optional[MigrationPlan] = None,
    ) -> ProjectState:
        return self._executor.migrate(migration_targets, plan=plan) 
开发者ID:wemake-services,项目名称:django-test-migrations,代码行数:8,代码来源:migrator.py


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