Python alembic.op 模块,rename_table() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用alembic.op.rename_table()

项目:tuning-box    作者:openstack    | 项目源码 | 文件源码
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'],
        )
项目:pygameweb    作者:pygame    | 项目源码 | 文件源码
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 ###
项目:reahl    作者:reahl    | 项目源码 | 文件源码
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)
项目:RSVPBot    作者:recursecenter    | 项目源码 | 文件源码
def upgrade():
    op.rename_table('event', 'events')
项目:RSVPBot    作者:recursecenter    | 项目源码 | 文件源码
def downgrade():
    op.rename_table('events', 'event')
项目:incubator-airflow-old    作者:apache    | 项目源码 | 文件源码
def upgrade():
    op.rename_table('user', 'users')
项目:incubator-airflow-old    作者:apache    | 项目源码 | 文件源码
def downgrade():
    op.rename_table('users', 'user')
项目:knowledge-repo    作者:airbnb    | 项目源码 | 文件源码
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))
项目:knowledge-repo    作者:airbnb    | 项目源码 | 文件源码
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')
项目:pygameweb    作者:pygame    | 项目源码 | 文件源码
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 ###
项目:airflow    作者:apache-airflow    | 项目源码 | 文件源码
def upgrade():
    op.rename_table('user', 'users')
项目:airflow    作者:apache-airflow    | 项目源码 | 文件源码
def downgrade():
    op.rename_table('users', 'user')
项目:collectors    作者:opentrials    | 项目源码 | 文件源码
def upgrade():
    for table in tables:
        op.rename_table('data_'+table, table)
项目:collectors    作者:opentrials    | 项目源码 | 文件源码
def downgrade():
    for table in tables:
        op.rename_table(table, 'data_'+table)
项目:collectors    作者:opentrials    | 项目源码 | 文件源码
def upgrade():
    for table in tables:
        op.rename_table(table, 'data_'+table)
项目:collectors    作者:opentrials    | 项目源码 | 文件源码
def downgrade():
    for table in tables:
        op.rename_table('data_'+table, table)
项目:collectors    作者:opentrials    | 项目源码 | 文件源码
def upgrade():
    op.rename_table('fda', 'fdadl')
项目:tuning-box    作者:openstack    | 项目源码 | 文件源码
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',
        ),
    )