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


Python op.get_bind方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    op.create_table(
        'project_locks',
        sa.Column('project_id',
                  sa.Integer,
                  sa.ForeignKey(
                    'projects.id', onupdate='CASCADE', ondelete='CASCADE'
                  ),
                  nullable=False,
                  primary_key=True
        ),
        sa.Column('lock_type',
                  sa.Enum(
                    'WORKER',
                    name='lock_type_enum'
                  ),
                  nullable=False,
                  primary_key=True
        )
    )

    # Add WORKER locks everywhere
    conn = op.get_bind()
    conn.execute("""INSERT INTO project_locks (project_id, lock_type)
                    SELECT id, 'WORKER' from projects""") 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:5179e99d35a5_add_lock_types.py

示例2: upgrade

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

    insp = inspect(conn)
    fk_names = [fk['name'] for fk in insp.get_foreign_keys('host')]
    if ("fk_hypervisor_id_resource_id" not in fk_names and
            "fk_host_id_resource_id" in fk_names):
        # NOTE(sileht): we are already good, the BD have been created from
        # scratch after "a54c57ada3f5"
        return

    op.drop_constraint("fk_hypervisor_id_resource_id", "host",
                       type_="foreignkey")
    op.drop_constraint("fk_hypervisor_history_resource_history_revision",
                       "host_history", type_="foreignkey")
    op.create_foreign_key("fk_host_id_resource_id", "host", "resource",
                          ["id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key("fk_host_history_resource_history_revision",
                          "host_history", "resource_history",
                          ["revision"], ["revision"], ondelete="CASCADE") 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:22,代码来源:ed9c6ddc5c35_fix_host_foreign_key.py

示例3: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    bind = op.get_bind()
    # NOTE(sileht): mysql can't delete an index on a foreign key
    # even this one is not the index used by the foreign key itself...
    # In our case we have two indexes fk_resource_history_id_resource_id and
    # and ix_resource_history_id, we want to delete only the second, but mysql
    # can't do that with a simple DROP INDEX ix_resource_history_id...
    # so we have to remove the constraint and put it back...
    if bind.engine.name == "mysql":
        op.drop_constraint("fk_resource_history_id_resource_id",
                           type_="foreignkey", table_name="resource_history")

    for table, colname in resource_tables + history_tables + other_tables:
        op.drop_index("ix_%s_%s" % (table, colname), table_name=table)

    if bind.engine.name == "mysql":
        op.create_foreign_key("fk_resource_history_id_resource_id",
                              "resource_history", "resource", ["id"], ["id"],
                              ondelete="CASCADE") 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:21,代码来源:a54c57ada3f5_removes_useless_indexes.py

示例4: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [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

示例5: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def downgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('pull_mirror', sa.Column('gitlab_id', sa.INTEGER(), nullable=True))

    for pull_mirror in session.query(PullMirror):
        pull_mirror.gitlab_id = pull_mirror.project.gitlab_id
        session.add(pull_mirror)
    session.commit()

    op.drop_constraint(None, 'pull_mirror', type_='foreignkey')
    op.drop_index(op.f('ix_pull_mirror_project_id'), table_name='pull_mirror')
    op.drop_column('pull_mirror', 'project_id')
    op.drop_index(op.f('ix_push_mirror_user_id'), table_name='push_mirror')
    op.drop_index(op.f('ix_push_mirror_project_id'), table_name='push_mirror')
    op.drop_table('push_mirror')
    op.drop_table('project')
    # ### end Alembic commands ### 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:21,代码来源:19e8725e0581_.py

示例6: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('domains',
                  sa.Column('allowed_docker_registries',
                            postgresql.ARRAY(sa.String()), nullable=True))
    # ### end Alembic commands ###

    print('\nSet default allowed_docker_registries.')
    allowed_registries = os.environ.get('ALLOWED_DOCKER_REGISTRIES', None)
    if allowed_registries:
        allowed_registries = allowed_registries.replace(' ', '')
        allowed_registries = '{index.docker.io,' + allowed_registries + '}'
    else:
        allowed_registries = '{index.docker.io}'
    connection = op.get_bind()
    query = ("UPDATE domains SET allowed_docker_registries = '{}';".format(allowed_registries))
    connection.execute(query)

    op.alter_column('domains', column_name='allowed_docker_registries',
                    nullable=False) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:22,代码来源:22e52d03fc61_add_allowed_docker_registries_in_domains.py

示例7: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    userstatus.create(op.get_bind())
    op.add_column(
        'users',
        sa.Column('status', sa.Enum(*userstatus_choices, name='userstatus'), nullable=True)
    )
    op.add_column('users', sa.Column('status_info', sa.Unicode(), nullable=True))

    # Set user's status field.
    conn = op.get_bind()
    query = textwrap.dedent(
        "UPDATE users SET status = 'active', status_info = 'migrated' WHERE is_active = 't';"
    )
    conn.execute(query)
    query = textwrap.dedent(
        "UPDATE users SET status = 'inactive', status_info = 'migrated' WHERE is_active <> 't';"
    )
    conn.execute(query)

    op.alter_column('users', column_name='status', nullable=False)
    op.drop_column('users', 'is_active') 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:23,代码来源:0d553d59f369_users_replace_is_active_to_status_and_its_info.py

示例8: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    agentstatus.create(op.get_bind())
    kernelstatus.create(op.get_bind())
    op.add_column('agents', sa.Column('lost_at', sa.DateTime(timezone=True), nullable=True))
    op.add_column('agents', sa.Column('status', sa.Enum('ALIVE', 'LOST', 'RESTARTING', 'TERMINATED', name='agentstatus'), nullable=False))
    op.create_index(op.f('ix_agents_status'), 'agents', ['status'], unique=False)
    op.add_column('kernels', sa.Column('agent_addr', sa.String(length=128), nullable=False))
    op.add_column('kernels', sa.Column('cpu_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('gpu_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('mem_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('repl_in_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('repl_out_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('stdin_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('stdout_port', sa.Integer(), nullable=False))
    op.drop_column('kernels', 'allocated_cores')
    op.add_column('kernels', sa.Column('cpu_set', sa.ARRAY(sa.Integer), nullable=True))
    op.add_column('kernels', sa.Column('gpu_set', sa.ARRAY(sa.Integer), nullable=True))
    op.alter_column('kernels', column_name='status', type_=sa.Enum(*kernelstatus_choices, name='kernelstatus'),
                    postgresql_using='status::kernelstatus') 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:21,代码来源:0f3bc98edaa0_more_status.py

示例9: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def downgrade():
    op.drop_column('kernels', 'stdout_port')
    op.drop_column('kernels', 'stdin_port')
    op.drop_column('kernels', 'repl_out_port')
    op.drop_column('kernels', 'repl_in_port')
    op.drop_column('kernels', 'mem_slot')
    op.drop_column('kernels', 'gpu_slot')
    op.drop_column('kernels', 'cpu_slot')
    op.drop_column('kernels', 'agent_addr')
    op.drop_index(op.f('ix_agents_status'), table_name='agents')
    op.drop_column('agents', 'status')
    op.drop_column('agents', 'lost_at')
    op.alter_column('kernels', column_name='status', type_=sa.String(length=64))
    op.add_column('kernels', sa.Column('allocated_cores', sa.ARRAY(sa.Integer), nullable=True))
    op.drop_column('kernels', 'cpu_set')
    op.drop_column('kernels', 'gpu_set')
    agentstatus.drop(op.get_bind())
    kernelstatus.drop(op.get_bind()) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:20,代码来源:0f3bc98edaa0_more_status.py

示例10: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    conn = op.get_bind()
    conn.execute('DROP INDEX IF EXISTS ix_kernels_unique_sess_token;')
    conn.execute('ALTER TYPE kernelstatus RENAME TO kernelstatus_old;')
    kernelstatus_new.create(conn)
    conn.execute(textwrap.dedent('''\
    ALTER TABLE kernels
        ALTER COLUMN "status" DROP DEFAULT,
        ALTER COLUMN "status" TYPE kernelstatus USING "status"::text::kernelstatus,
        ALTER COLUMN "status" SET DEFAULT 'PENDING'::kernelstatus;
    DROP TYPE kernelstatus_old;
    '''))
    op.create_index(
        'ix_kernels_unique_sess_token', 'kernels', ['access_key', 'sess_id'],
        unique=True, postgresql_where=sa.text(
            "status NOT IN ('TERMINATED', 'CANCELLED') and role = 'master'"
        )) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:19,代码来源:513164749de4_add_cancelled_to_kernelstatus.py

示例11: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def downgrade():
    op.drop_index('ix_kernels_unique_sess_token', table_name='kernels')
    conn = op.get_bind()
    conn.execute('ALTER TYPE kernelstatus RENAME TO kernelstatus_new;')
    kernelstatus_old.create(conn)
    conn.execute(textwrap.dedent('''\
    ALTER TABLE kernels
        ALTER COLUMN "status" DROP DEFAULT,
        ALTER COLUMN "status" TYPE kernelstatus USING (
            CASE "status"::text
                WHEN 'CANCELLED' THEN 'TERMINATED'
                ELSE "status"::text
            END
        )::kernelstatus,
        ALTER COLUMN "status" SET DEFAULT 'PREPARING'::kernelstatus;
    DROP TYPE kernelstatus_new;
    '''))
    op.create_index(
        'ix_kernels_unique_sess_token', 'kernels', ['access_key', 'sess_id'],
        unique=True, postgresql_where=sa.text(
            "status != 'TERMINATED' and role = 'master'"
        )) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:24,代码来源:513164749de4_add_cancelled_to_kernelstatus.py

示例12: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('domains', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.alter_column('domains', 'total_resource_slots',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    nullable=True)
    op.add_column('groups', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.add_column('groups', sa.Column('total_resource_slots',
                                      postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    op.add_column('users', sa.Column('integration_id', sa.String(length=512), nullable=True))
    # ### end Alembic commandk ###

    print('\nSet group\'s total_resource_slots with empty dictionary.')
    query = textwrap.dedent('''\
        UPDATE groups SET total_resource_slots = '{}'::jsonb;
    ''')
    connection = op.get_bind()
    connection.execute(query) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:20,代码来源:22964745c12b_add_total_resource_slots_to_group.py

示例13: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###

    userrole_choices = list(map(lambda v: v.value, UserRole))
    if 'superadmin' in userrole_choices:
        userrole_choices.remove('superadmin')
        conn = op.get_bind()

        # First, change all superadmin role to admin.
        query = textwrap.dedent("UPDATE users SET role = 'admin' WHERE role = 'superadmin';")
        conn.execute(query)

        # Remove superadmin from user role choices.
        conn.execute('ALTER TYPE userrole RENAME TO userrole___;')
        conn.execute('CREATE TYPE userrole as enum (%s)' % ("'" + "','".join(userrole_choices) + "'"))
        conn.execute(textwrap.dedent('''\
            ALTER TABLE users
                ALTER COLUMN role TYPE userrole USING role::text::userrole;
        '''))
        conn.execute('DROP TYPE userrole___;') 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:24,代码来源:e18ed5fcfedf_add_superadmin_role_for_user.py

示例14: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_bind [as 别名]
def upgrade():
    op.add_column('keypairs', sa.Column('ssh_public_key', sa.String(length=750), nullable=True))
    op.add_column('keypairs', sa.Column('ssh_private_key', sa.String(length=2000), nullable=True))

    # partial table to be preserved and referred
    metadata = sa.MetaData(naming_convention=convention)
    keypairs = sa.Table(
        'keypairs', metadata,
        sa.Column('access_key', sa.String(length=20), primary_key=True),
        sa.Column('ssh_public_key', sa.String(length=750), nullable=True),
        sa.Column('ssh_private_key', sa.String(length=2000), nullable=True),
    )

    # Fill in SSH keypairs in every keypairs.
    conn = op.get_bind()
    query = sa.select([keypairs.c.access_key]).select_from(keypairs)
    rows = conn.execute(query).fetchall()
    for row in rows:
        pubkey, privkey = generate_ssh_keypair()
        query = (sa.update(keypairs)
                   .values(ssh_public_key=pubkey, ssh_private_key=privkey)
                   .where(keypairs.c.access_key == row.access_key))
        conn.execute(query) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:25,代码来源:0262e50e90e0_add_ssh_keypair_into_keypair.py

示例15: upgrade

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

    fks_to_cascade = {
        'sfc_flow_classifier_l7_parameters': 'classifier_id',
        'sfc_chain_group_associations': 'portchain_id',
        'sfc_port_chain_parameters': 'chain_id',
        'sfc_service_function_params': 'pair_id',
        'sfc_chain_classifier_associations': 'portchain_id'
    }

    for table, column in fks_to_cascade.items():
        fk_constraints = inspector.get_foreign_keys(table)
        for fk in fk_constraints:
            if column in fk['constrained_columns']:
                fk['options']['ondelete'] = 'CASCADE'
                migration.remove_foreign_keys(table, fk_constraints)
                migration.create_foreign_keys(table, fk_constraints) 
开发者ID:openstack,项目名称:networking-sfc,代码行数:20,代码来源:06382790fb2c_fix_foreign_constraints.py


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