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


Python op.create_unique_constraint方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    op.add_column("resource_type", sa.Column('tablename', sa.String(18),
                                             nullable=True))

    resource_type = sa.Table(
        'resource_type', sa.MetaData(),
        sa.Column('name', sa.String(255), nullable=False),
        sa.Column('tablename', sa.String(18), nullable=True)
    )
    op.execute(resource_type.update().where(
        resource_type.c.name == "instance_network_interface"
    ).values({'tablename': op.inline_literal("'instance_net_int'")}))
    op.execute(resource_type.update().where(
        resource_type.c.name != "instance_network_interface"
    ).values({'tablename': resource_type.c.name}))

    op.alter_column("resource_type", "tablename", type_=sa.String(18),
                    nullable=False)
    op.create_unique_constraint("uniq_resource_type0tablename",
                                "resource_type", ["tablename"]) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:22,代码来源:0718ed97e5b3_add_tablename_to_resource_type.py

示例2: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    op.add_column('compute_node',
                  sa.Column('rp_uuid', sa.String(length=36), nullable=True))
    op.create_unique_constraint('uniq_compute_node0rp_uuid',
                                'compute_node', ['rp_uuid'])

    # perform data migration between tables
    session = sa.orm.Session(bind=op.get_bind())
    with session.begin(subtransactions=True):
        for row in session.query(COMPUTE_NODE_TABLE):
            session.execute(
                COMPUTE_NODE_TABLE.update().values(
                    rp_uuid=row.uuid).where(
                        COMPUTE_NODE_TABLE.c.uuid == row.uuid)
            )
    # this commit is necessary to allow further operations
    session.commit()

    op.alter_column('compute_node', 'rp_uuid',
                    nullable=False,
                    existing_type=sa.String(length=36),
                    existing_nullable=True,
                    existing_server_default=False) 
开发者ID:openstack,项目名称:zun,代码行数:25,代码来源:d502ce8fb705_add_rp_uuid_to_compute_node.py

示例3: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    op.create_table('sfc_port_pair_group_params',
                    sa.Column('keyword', sa.String(length=255),
                              nullable=False),
                    sa.Column('value', sa.String(length=255),
                              nullable=True),
                    sa.Column('pair_group_id', sa.String(length=36),
                              nullable=False),
                    sa.ForeignKeyConstraint(['pair_group_id'],
                                            ['sfc_port_pair_groups.id'],
                                            ondelete='CASCADE'),
                    sa.PrimaryKeyConstraint('keyword', 'pair_group_id'),
                    mysql_engine='InnoDB'
                    )
    op.add_column('sfc_port_chains', sa.Column('chain_id',
                  sa.Integer(), nullable=False))
    op.create_unique_constraint(None, 'sfc_port_chains', ['chain_id'])
    op.add_column('sfc_port_pair_groups', sa.Column('group_id',
                  sa.Integer(), nullable=False))
    op.create_unique_constraint(None, 'sfc_port_pair_groups', ['group_id']) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:22,代码来源:fa75d46a7f11_add_port_pair_group_params.py

示例4: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    ''' Remove column access_id from user_projects and projects_groups '''

    # this removes the current constraints as well.
    op.drop_column('user_projects', 'access')
    op.drop_column('projects_groups', 'access')

    # recreate the previous constraints
    op.create_unique_constraint(
            None,
            'user_projects',
            ['project_id', 'user_id'],
    )
    op.create_primary_key(
            None,
            'projects_groups',
            ['project_id', 'group_id'],
    )
    op.drop_table('access_levels') 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:987edda096f5_access_id_in_user_projects.py

示例5: batch_create_unique_constraint

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def batch_create_unique_constraint(
            cls, operations, constraint_name, columns, **kw):
        """Issue a "create unique constraint" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.create_unique_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        """
        kw['schema'] = operations.impl.schema
        op = cls(
            constraint_name, operations.impl.table_name, columns,
            **kw
        )
        return operations.invoke(op) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:ops.py

示例6: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('rss_parser_funcs', 'func',
               existing_type=sa.TEXT(),
               nullable=False)
    op.add_column('rss_parser_feed_name_lut_version', sa.Column('feed_name', sa.TEXT(), autoincrement=False, nullable=True))
    op.create_index('ix_rss_parser_feed_name_lut_version_feed_name', 'rss_parser_feed_name_lut_version', ['feed_name'], unique=False)
    op.drop_index(op.f('ix_rss_parser_feed_name_lut_version_feed_id'), table_name='rss_parser_feed_name_lut_version')
    op.drop_column('rss_parser_feed_name_lut_version', 'feed_id')
    op.add_column('rss_parser_feed_name_lut', sa.Column('feed_name', sa.TEXT(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'rss_parser_feed_name_lut', type_='foreignkey')
    op.create_foreign_key('rss_parser_feed_name_lut_feed_name_fkey', 'rss_parser_feed_name_lut', 'rss_parser_funcs', ['feed_name'], ['feed_name'])
    op.drop_constraint(None, 'rss_parser_feed_name_lut', type_='unique')
    op.create_unique_constraint('rss_parser_feed_name_lut_feed_netloc_feed_name_key', 'rss_parser_feed_name_lut', ['feed_netloc', 'feed_name'])
    op.create_index('ix_rss_parser_feed_name_lut_feed_name', 'rss_parser_feed_name_lut', ['feed_name'], unique=False)
    op.drop_index(op.f('ix_rss_parser_feed_name_lut_feed_id'), table_name='rss_parser_feed_name_lut')
    op.drop_column('rss_parser_feed_name_lut', 'feed_id')
    ### end Alembic commands ### 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:20,代码来源:00027_c92e0c8632d7_more_rss_stuff.py

示例7: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('output_file', sa.Column('uploaded_movie_url', sa.VARCHAR(length=600), autoincrement=False, nullable=True))
    op.add_column('output_file', sa.Column('uploaded_movie_name', sa.VARCHAR(length=150), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'output_file', type_='foreignkey')
    op.drop_constraint('output_file_uc', 'output_file', type_='unique')
    op.create_unique_constraint('output_file_uc', 'output_file', ['name', 'entity_id', 'output_type_id', 'task_type_id', 'representation', 'revision'])
    op.drop_column('output_file', 'temporal_entity_id')
    op.drop_constraint(None, 'asset_instance', type_='foreignkey')
    op.create_index('ix_asset_instance_entity_type_id', 'asset_instance', ['entity_type_id'], unique=False)
    op.create_index('ix_asset_instance_entity_id', 'asset_instance', ['entity_id'], unique=False)
    op.drop_constraint('asset_instance_uc', 'asset_instance', type_='unique')
    op.create_unique_constraint('asset_instance_uc', 'asset_instance', ['asset_id', 'entity_id', 'number'])
    op.drop_constraint('asset_instance_name_uc', 'asset_instance', type_='unique')
    op.create_unique_constraint('asset_instance_name_uc', 'asset_instance', ['entity_id', 'name'])
    op.drop_index(op.f('ix_asset_instance_scene_id'), table_name='asset_instance')
    op.alter_column('asset_instance', 'entity_type_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.alter_column('asset_instance', 'entity_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.drop_column('asset_instance', 'scene_id')
    op.drop_table('asset_instance_link')
    # ### end Alembic commands ### 
开发者ID:cgwire,项目名称:zou,代码行数:27,代码来源:ee2373fbe3a4_.py

示例8: batch_create_unique_constraint

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def batch_create_unique_constraint(
        cls, operations, constraint_name, columns, **kw
    ):
        """Issue a "create unique constraint" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.create_unique_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        """
        kw["schema"] = operations.impl.schema
        op = cls(constraint_name, operations.impl.table_name, columns, **kw)
        return operations.invoke(op) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:24,代码来源:ops.py

示例9: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_notification_statistics_day'), table_name='notification_statistics')
    op.drop_constraint('uix_service_to_day', 'notification_statistics')

    op.alter_column('notification_statistics', 'day', new_column_name='day_date')
    op.add_column('notification_statistics', sa.Column('day', sa.String(), nullable=True))

    op.get_bind()
    op.execute("UPDATE notification_statistics ns1 SET day = (SELECT to_char(day_date, 'YYYY-MM-DD') FROM notification_statistics ns2 WHERE ns1.id = ns2.id)")

    op.alter_column('notification_statistics', 'day', nullable=False)
    op.drop_column('notification_statistics', 'day_date')
    op.create_unique_constraint('uix_service_to_day', 'notification_statistics', columns=['service_id', 'day'])

    ### end Alembic commands ### 
开发者ID:alphagov,项目名称:notifications-api,代码行数:18,代码来源:0004_notification_stats_date.py

示例10: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('app_user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=255), nullable=True),
    sa.Column('password', sa.String(length=255), nullable=True),
    sa.Column('active', sa.Boolean(), nullable=True),
    sa.Column('is_admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email')
    )
    op.create_table('password_reset',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('code', sa.String(length=255), nullable=True),
    sa.Column('date', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['app_user.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('code')
    )
    ### end Alembic commands ###

    op.create_unique_constraint('unique_user_code', 'password_reset', ['user_id', 'code']) 
开发者ID:projectweekend,项目名称:Flask-PostgreSQL-API-Seed,代码行数:25,代码来源:351c26992f23_.py

示例11: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint('use_of_force_incidents_opaque_id_key', 'use_of_force_incidents', ['opaque_id'])
    op.create_unique_constraint('citizen_complaint_opaque_id_key', 'citizen_complaint', ['opaque_id'])
    ### end Alembic commands ### 
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:4137d3521d5_.py

示例12: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('password_reset_uuid', sa.String(length=36), nullable=True))
    op.create_unique_constraint(None, 'users', ['password_reset_uuid'])
    ### end Alembic commands ### 
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:4e98ea7e43d_.py

示例13: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    connection = op.get_bind()

    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('departments', sa.Column('short_name', sa.String(length=80), nullable=True))
    op.create_unique_constraint("dept_short_name", 'departments', ['short_name'])
    ### end Alembic commands ### 
开发者ID:codeforamerica,项目名称:comport,代码行数:9,代码来源:16b50a2c53b_.py

示例14: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint('users_email_key', 'users', ['email'])
    ### end Alembic commands ### 
开发者ID:codeforamerica,项目名称:comport,代码行数:6,代码来源:22a9ff0220c_.py

示例15: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_unique_constraint [as 别名]
def upgrade():
    op.add_column('resource_class',
                  sa.Column('uuid', sa.String(length=36), nullable=False))
    op.create_unique_constraint('uniq_resource_class0uuid',
                                'resource_class', ['uuid'])
    op.drop_index('uniq_container0name', table_name='resource_class') 
开发者ID:openstack,项目名称:zun,代码行数:8,代码来源:8192905fd835_add_uuid_to_resource_class.py


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