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