本文整理汇总了Python中alembic.op.create_primary_key方法的典型用法代码示例。如果您正苦于以下问题:Python op.create_primary_key方法的具体用法?Python op.create_primary_key怎么用?Python op.create_primary_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.op
的用法示例。
在下文中一共展示了op.create_primary_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def upgrade():
op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('pk_kernels', 'kernels', type_='primary')
op.add_column('kernels',
sa.Column('id', GUID(),
server_default=sa.text('uuid_generate_v4()'),
nullable=False))
op.add_column('kernels', sa.Column('role', sa.String(length=16), nullable=False, default='master'))
op.create_primary_key('pk_kernels', 'kernels', ['id'])
op.alter_column(
'kernels', 'sess_id',
existing_type=postgresql.UUID(),
type_=sa.String(length=64),
nullable=True,
existing_server_default=sa.text('uuid_generate_v4()'))
op.create_index(op.f('ix_kernels_sess_id'), 'kernels', ['sess_id'], unique=False)
op.create_index(op.f('ix_kernels_sess_id_role'), 'kernels', ['sess_id', 'role'], unique=False)
op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders',
'vfolder_attachment', 'vfolders',
['vfolder'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
op.create_foreign_key('fk_vfolder_attachment_kernel_kernels',
'vfolder_attachment', 'kernels',
['kernel'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
示例2: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey')
op.drop_constraint('pk_kernels', 'kernels', type_='primary')
op.drop_index(op.f('ix_kernels_sess_id'), table_name='kernels')
op.drop_index(op.f('ix_kernels_sess_id_role'), table_name='kernels')
op.alter_column(
'kernels', 'sess_id',
existing_type=sa.String(length=64),
type_=postgresql.UUID(),
nullable=False,
existing_server_default=sa.text('uuid_generate_v4()'),
postgresql_using='sess_id::uuid')
op.create_primary_key('pk_kernels', 'kernels', ['sess_id'])
op.drop_column('kernels', 'id')
op.drop_column('kernels', 'role')
op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders',
'vfolder_attachment', 'vfolders',
['vfolder'], ['id'])
op.create_foreign_key('fk_vfolder_attachment_kernel_kernels',
'vfolder_attachment', 'kernels',
['kernel'], ['sess_id'])
示例3: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [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')
示例4: batch_create_primary_key
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def batch_create_primary_key(cls, operations, constraint_name, columns):
"""Issue a "create primary key" instruction using the
current batch migration context.
The batch form of this call omits the ``table_name`` and ``schema``
arguments from the call.
.. seealso::
:meth:`.Operations.create_primary_key`
"""
op = cls(
constraint_name, operations.impl.table_name, columns,
schema=operations.impl.schema
)
return operations.invoke(op)
示例5: create_followers_to_followings_table
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def create_followers_to_followings_table() -> None:
op.create_table(
"followers_to_followings",
sa.Column(
"follower_id",
sa.Integer,
sa.ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"following_id",
sa.Integer,
sa.ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
),
)
op.create_primary_key(
"pk_followers_to_followings",
"followers_to_followings",
["follower_id", "following_id"],
)
示例6: create_articles_to_tags_table
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def create_articles_to_tags_table() -> None:
op.create_table(
"articles_to_tags",
sa.Column(
"article_id",
sa.Integer,
sa.ForeignKey("articles.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"tag",
sa.Text,
sa.ForeignKey("tags.tag", ondelete="CASCADE"),
nullable=False,
),
)
op.create_primary_key(
"pk_articles_to_tags", "articles_to_tags", ["article_id", "tag"]
)
示例7: create_favorites_table
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def create_favorites_table() -> None:
op.create_table(
"favorites",
sa.Column(
"user_id",
sa.Integer,
sa.ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"article_id",
sa.Integer,
sa.ForeignKey("articles.id", ondelete="CASCADE"),
nullable=False,
),
)
op.create_primary_key("pk_favorites", "favorites", ["user_id", "article_id"])
示例8: batch_create_primary_key
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def batch_create_primary_key(cls, operations, constraint_name, columns):
"""Issue a "create primary key" instruction using the
current batch migration context.
The batch form of this call omits the ``table_name`` and ``schema``
arguments from the call.
.. seealso::
:meth:`.Operations.create_primary_key`
"""
op = cls(
constraint_name,
operations.impl.table_name,
columns,
schema=operations.impl.schema,
)
return operations.invoke(op)
示例9: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
"""Down migration."""
# Drop all the new stuff
op.drop_index(op.f('ix_change_removed_tags_tag_name'), table_name='change_removed_tags')
op.drop_index(op.f('ix_change_removed_tags_change_id'), table_name='change_removed_tags')
op.drop_table('change_removed_tags')
op.drop_index(op.f('ix_change_added_tags_tag_name'), table_name='change_added_tags')
op.drop_index(op.f('ix_change_added_tags_change_id'), table_name='change_added_tags')
op.drop_table('change_added_tags')
# Restore the old tag primary key constraint stuff
op.drop_constraint('sticker_tag_tag_name_fkey', 'sticker_tag', type_='foreignkey')
op.drop_column('sticker_tag', 'tag_is_default_language')
op.drop_constraint('tag_pkey', 'tag')
op.create_primary_key('tag_pkey', 'tag', ['name'])
op.create_foreign_key(
'sticker_tag_tag_name_fkey',
'sticker_tag', 'tag',
['tag_name'], ['name'],
onupdate='CASCADE', ondelete='CASCADE', deferrable=True
)
# ### end Alembic commands ###
示例10: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
# Drop New Index
op.drop_index('ix_user_email', 'user')
# Rename email column
op.alter_column('user', 'email', new_column_name='user_id')
# Rename admin column
op.alter_column('user', 'is_admin', new_column_name='admin')
# Drop date columns
op.drop_column('user', 'created_at')
op.drop_column('user', 'updated_at')
# Drop new ID Column
op.drop_column('user', 'id')
# Reinstate OLD PKey
op.create_primary_key("user_pkey", "user", ["user_id", ])
示例11: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
# Remove new foreign key reference
op.drop_constraint('group_owner_email_fkey', 'group', type_='foreignkey')
# Drop New Index
op.drop_index('_group_uc_name_owner_email', 'group')
# Rename email column
op.alter_column('group', 'owner_email', new_column_name='owner_id')
# Drop date columns
op.drop_column('group', 'created_at')
op.drop_column('group', 'updated_at')
# Drop new ID Column
op.drop_column('group', 'id')
# Reinstate OLD PKey
op.create_primary_key("group_pkey", "group", ["group_id", "owner_id" ])
pass
示例12: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def upgrade():
op.add_column('container_secret',
sa.Column('created_at', sa.DateTime(), nullable=False))
op.add_column('container_secret',
sa.Column('deleted', sa.Boolean(), nullable=False))
op.add_column('container_secret',
sa.Column('deleted_at', sa.DateTime(), nullable=True))
op.add_column('container_secret',
sa.Column('id', sa.String(length=36), nullable=False))
op.add_column('container_secret',
sa.Column('status', sa.String(length=20), nullable=False))
op.add_column('container_secret',
sa.Column('updated_at', sa.DateTime(), nullable=False))
op.create_primary_key('pk_container_secret', 'container_secret', ['id'])
op.create_unique_constraint(
'_container_secret_name_uc',
'container_secret',
['container_id', 'secret_id', 'name']
)
示例13: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
op.drop_constraint('fk_vuln', 'vulnerability_git_commits', type_='foreignkey')
op.create_index('uk_ver_cve_id', 'vulnerability', ['version', 'cve_id'], unique=True)
op.drop_constraint('uk_vcdb_id_version', 'vulnerability', type_='unique')
op.drop_column('vulnerability', 'vcdb_id')
op.drop_column('vulnerability', 'prev_version')
op.alter_column('vulnerability', 'version',
existing_type=mysql.INTEGER(display_width=11),
nullable=False)
# Drop all foreign keys on vulnerability.id as we intend to update it.
op.drop_constraint('vulnerability_git_commits_ibfk_1', 'vulnerability_git_commits', type_='foreignkey')
##############
# Update the vulnerability primary key.
# Remove autoincrement from the PK as there can only be one auto key and it has to be the PK.
op.alter_column('vulnerability', 'id', existing_type=sa.Integer(), autoincrement=False, nullable=False)
op.drop_constraint('id', 'vulnerability', type_='primary')
# Now we can define a new primary key.
op.create_primary_key('pk', 'vulnerability', ['id', 'version'])
# Re-enable auto incrementing for the id column, too.
op.alter_column('vulnerability', 'id', existing_type=sa.Integer(), autoincrement=True, nullable=False)
# ----------------------------------------------------------------------------------------------------
op.add_column('vulnerability_git_commits', sa.Column('version', sa.Integer(), nullable=False))
op.create_foreign_key('fk_vuln', 'vulnerability_git_commits', 'vulnerability', ['vulnerability_details_id', 'version'], ['id', 'version'])
# ### end Alembic commands ###
示例14: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def downgrade():
op.drop_constraint('fk_vuln', 'vulnerability_git_commits', type_='foreignkey')
op.alter_column('vulnerability_git_commits', 'vulnerability_details_id',
existing_type=mysql.INTEGER(display_width=11),
nullable=True)
op.drop_column('vulnerability_git_commits', 'version')
op.drop_index(op.f('ix_vulnerability_cve_id'), table_name='vulnerability')
op.drop_constraint('uk_ver_cve_id', 'vulnerability', type_='unique')
op.create_index('cve_id', 'vulnerability', ['cve_id'], unique=True)
# Remove autoincrement from the PK as there can only be one auto key and it has to be the PK.
op.alter_column('vulnerability', 'id', existing_type=sa.Integer(), autoincrement=False, nullable=False)
op.drop_constraint('pk', 'vulnerability', type_='primary')
op.create_primary_key('id', 'vulnerability', ['id'])
op.alter_column('vulnerability', 'id', existing_type=sa.Integer(), autoincrement=True, nullable=False)
op.drop_column('vulnerability', 'version')
op.drop_column('vulnerability', 'state')
op.drop_constraint('fk_reviewer_id', 'vulnerability', type_='foreignkey')
op.drop_column('vulnerability', 'reviewer_id')
op.drop_column('vulnerability', 'review_feedback')
op.add_column('vulnerability_resources', sa.Column('vulnerability_details_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
op.create_foreign_key('vulnerability_resources_ibfk_1', 'vulnerability_resources', 'vulnerability', ['vulnerability_details_id'], ['id'])
op.create_foreign_key('vulnerability_git_commits_ibfk_1', 'vulnerability_git_commits', 'vulnerability', ['vulnerability_details_id'], ['id'])
示例15: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import create_primary_key [as 别名]
def upgrade():
op.add_column('listener_statistics',
sa.Column('amphora_id',
sa.String(36),
nullable=False)
)
op.drop_constraint('fk_listener_statistics_listener_id',
'listener_statistics',
type_='foreignkey')
op.drop_constraint('PRIMARY',
'listener_statistics',
type_='primary')
op.create_primary_key('pk_listener_statistics', 'listener_statistics',
['listener_id', 'amphora_id'])
op.create_foreign_key('fk_listener_statistics_listener_id',
'listener_statistics',
'listener',
['listener_id'],
['id'])
op.create_foreign_key('fk_listener_statistic_amphora_id',
'listener_statistics',
'amphora',
['amphora_id'],
['id'])