def upgrade():
table_prefix = context.config.get_main_option('table_prefix')
op.drop_table(table_prefix + 'template')
table_name = table_prefix + 'environment_schema_values'
with op.batch_alter_table(table_name) as batch:
batch.drop_constraint(table_name + '_schema_id_fkey', 'foreignkey')
batch.alter_column(
'schema_id',
new_column_name='resource_definition_id',
existing_type=sa.Integer(),
)
op.rename_table(table_name, table_prefix + 'resource_values')
op.rename_table(table_prefix + 'schema',
table_prefix + 'resource_definition')
with op.batch_alter_table(table_prefix + 'resource_definition') as batch:
batch.drop_column('namespace_id')
op.drop_table(table_prefix + 'namespace')
table_name = table_prefix + 'resource_values'
with op.batch_alter_table(table_name) as batch:
batch.create_foreign_key(
table_name + '_resource_definition_id_fkey',
table_prefix + 'resource_definition',
['resource_definition_id'],
['id'],
)
python类rename_table()的实例源码
6cb6a6a151b7_removed_unused_page_tables_and_fields.py 文件源码
项目:pygameweb
作者: pygame
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('skin')
op.drop_table('modules')
op.drop_column('node', 'mods')
op.drop_column('node', 'parentid')
op.drop_column('node', 'folderid')
op.drop_column('node', 'image')
op.drop_column('node', 'folder')
op.drop_column('node', 'custom')
op.drop_column('node', 'target')
op.drop_column('node', 'type')
op.drop_column('node', 'skin_id')
op.drop_column('node', 'modules_id')
op.rename_table('node', 'page')
op.execute('ALTER SEQUENCE node_id_seq RENAME TO page_id_seq')
# ### end Alembic commands ###
def rename_link_table(self):
old_table_name = 'requirement_deferred_actions__deferredaction_requirements'
new_table_name = 'deferredaction_requirement'
# Rename table itself
self.schedule('alter', op.rename_table, old_table_name, new_table_name)
# Rename of foreign key names
for old_name, other_table_name in [
('deferredaction_requirements_fk', 'deferredaction'),
('requirement_deferred_actions_fk', 'requirement') ]:
column_name = '%s_id' % other_table_name
new_name = fk_name(new_table_name, column_name, other_table_name)
self.schedule('drop_fk', op.drop_constraint, old_name, old_table_name)
self.schedule('create_fk', op.create_foreign_key, new_name, new_table_name, other_table_name, [column_name], ['id'])
# Primary keys are renamed according to new naming convention - in this case the table too
self.rename_pk(new_table_name, ['deferredaction_id', 'requirement_id'], old_table_name=old_table_name)
753e7343bbf9_rename_table_to_events.py 文件源码
项目:RSVPBot
作者: recursecenter
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def upgrade():
op.rename_table('event', 'events')
753e7343bbf9_rename_table_to_events.py 文件源码
项目:RSVPBot
作者: recursecenter
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def downgrade():
op.rename_table('events', 'event')
2e82aab8ef20_rename_user_table.py 文件源码
项目:incubator-airflow-old
作者: apache
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def upgrade():
op.rename_table('user', 'users')
2e82aab8ef20_rename_user_table.py 文件源码
项目:incubator-airflow-old
作者: apache
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def downgrade():
op.rename_table('users', 'user')
1b385158fd32_assoc_rename_and_uuid_column.py 文件源码
项目:knowledge-repo
作者: airbnb
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def upgrade():
op.rename_table('knowledge_post_author', 'assoc_post_author')
op.rename_table('knowledge_post_tags', 'assoc_post_tag')
op.add_column('assoc_post_author', sa.Column('order', sa.Integer(), nullable=True))
op.add_column('posts', sa.Column('uuid', sa.String(length=100), nullable=True))
op.create_unique_constraint(None, 'posts', ['uuid'])
op.add_column('pageviews', sa.Column('object_action', sa.String(length=100), nullable=True))
op.add_column('pageviews', sa.Column('version', sa.String(length=100), nullable=True))
1b385158fd32_assoc_rename_and_uuid_column.py 文件源码
项目:knowledge-repo
作者: airbnb
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def downgrade():
op.drop_column('assoc_post_author', 'order')
op.rename_table('assoc_post_author', 'knowledge_post_author')
op.rename_table('assoc_post_tag', 'knowledge_post_tags')
op.drop_constraint(None, 'posts', type_='unique')
op.drop_column('posts', 'uuid')
op.drop_column('pageviews', 'object_action')
op.drop_column('pageviews', 'version')
6cb6a6a151b7_removed_unused_page_tables_and_fields.py 文件源码
项目:pygameweb
作者: pygame
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('node', sa.Column('modules_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('skin_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('type', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('target', sa.VARCHAR(length=80), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('custom', postgresql.BYTEA(), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('folder', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('image', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('folderid', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('parentid', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('node', sa.Column('mods', sa.INTEGER(), autoincrement=False, nullable=True))
op.rename_table('page', 'node')
op.execute('ALTER SEQUENCE page_id_seq RENAME TO node_id_seq')
op.create_table('modules',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(length=80), autoincrement=False, nullable=True),
sa.Column('title', sa.VARCHAR(length=80), autoincrement=False, nullable=True),
sa.Column('orders', sa.INTEGER(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='modules_pkey')
)
op.create_table('skin',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('title', sa.VARCHAR(length=80), autoincrement=False, nullable=True),
sa.Column('fname', sa.VARCHAR(length=80), autoincrement=False, nullable=True),
sa.Column('orders', sa.INTEGER(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='skin_pkey')
)
# ### end Alembic commands ###
def upgrade():
op.rename_table('user', 'users')
def downgrade():
op.rename_table('users', 'user')
20160323090938_remove_data_prefix_from_tables.py 文件源码
项目:collectors
作者: opentrials
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def upgrade():
for table in tables:
op.rename_table('data_'+table, table)
20160323090938_remove_data_prefix_from_tables.py 文件源码
项目:collectors
作者: opentrials
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def downgrade():
for table in tables:
op.rename_table(table, 'data_'+table)
20160311153848_add_data_prefix_to_tables.py 文件源码
项目:collectors
作者: opentrials
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def upgrade():
for table in tables:
op.rename_table(table, 'data_'+table)
20160311153848_add_data_prefix_to_tables.py 文件源码
项目:collectors
作者: opentrials
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def downgrade():
for table in tables:
op.rename_table('data_'+table, table)
20160510091510_fda_rename_table_to_fdadl.py 文件源码
项目:collectors
作者: opentrials
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def upgrade():
op.rename_table('fda', 'fdadl')
def downgrade():
table_prefix = context.config.get_main_option('table_prefix')
table_name = table_prefix + 'resource_values'
with op.batch_alter_table(table_name) as batch:
batch.drop_constraint(table_name + '_resource_definition_id_fkey',
'foreignkey')
op.create_table(
table_prefix + 'namespace',
sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
sa.Column('name', sa.String(length=128), nullable=True),
)
table_name = table_prefix + 'schema'
op.rename_table(table_prefix + 'resource_definition', table_name)
with op.batch_alter_table(table_name) as batch:
batch.add_column(
sa.Column('namespace_id', sa.Integer(), nullable=True))
table_name = table_prefix + 'environment_schema_values'
op.rename_table(table_prefix + 'resource_values', table_name)
with op.batch_alter_table(table_name) as batch:
batch.alter_column(
'resource_definition_id',
new_column_name='schema_id',
existing_type=sa.Integer(),
)
batch.create_foreign_key(
table_name + '_schema_id_fkey',
table_prefix + 'schema',
['schema_id'],
['id'],
)
table_name = table_prefix + 'template'
op.create_table(
table_name,
sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
sa.Column('name', sa.String(length=128), nullable=True),
sa.Column('component_id', sa.Integer(), nullable=True),
sa.Column('content', tuning_box.db.Json(), nullable=True),
sa.ForeignKeyConstraint(
['component_id'], [table_prefix + 'component.id'],
name=table_name + '_component_id_fkey',
),
)