本文整理汇总了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"])
示例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)
示例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'])
示例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')
示例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)
示例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 ###
示例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 ###
示例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)
示例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 ###
示例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'])
示例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 ###
示例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 ###
示例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 ###
示例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 ###
示例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')