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


Python op.get_context方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    # Workaround for following alembic bug:
    # https://bitbucket.org/zzzeek/alembic/issue/89
    context = op.get_context()
    if context.bind.dialect.name == 'postgresql':
        op.execute(
            "CREATE TYPE %s AS ENUM ('%s', '%s')" % (
                ATTR_NAME, ENUM_POOL_VALUE, ENUM_HOST_VALUE))

    op.add_column(
        SG_TABLE_NAME,
        sa.Column(
            ATTR_NAME,
            sa.Enum(ENUM_POOL_VALUE, ENUM_HOST_VALUE, name=ATTR_NAME),
            nullable=True,
        ),
    ) 
开发者ID:openstack,项目名称:manila,代码行数:19,代码来源:d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py

示例2: upgrade

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

    ctx = op.get_context()
    con = op.get_bind()

    op.alter_column('secret_acls', 'creator_only', existing_type=sa.BOOLEAN(),
                    new_column_name='project_access')

    # reverse existing flag value as project_access is negation of creator_only
    op.execute('UPDATE secret_acls SET project_access = NOT project_access',
               execution_options={'autocommit': True})

    op.alter_column('container_acls', 'creator_only',
                    existing_type=sa.BOOLEAN(),
                    new_column_name='project_access')

    # reverse existing flag value as project_access is negation of creator_only
    op.execute('UPDATE container_acls SET project_access = NOT project_access',
               execution_options={'autocommit': True}) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:21,代码来源:6a4457517a3_rename_acl_creator_only_to_project_.py

示例3: upgrade

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

    # Get relevant tables
    secrets = metadata.tables['secrets']
    project_secret = metadata.tables['project_secret']

    # Add project_id to the secrets
    op.execute(secrets.update().
               values({'project_id': project_secret.c.project_id}).
               where(secrets.c.id == project_secret.c.secret_id).
               where(secrets.c.project_id == None)
               )

    # Need to drop foreign key constraint before mysql will allow changes
    ctx = op.get_context()
    _drop_constraint(ctx, 'secrets_project_fk', 'secrets')

    # make project_id no longer nullable
    op.alter_column('secrets', 'project_id',
                    type_=sa.String(36), nullable=False)

    # Create foreign key constraint again
    _create_constraint(ctx, 'secrets_project_fk', 'secrets', 'projects',
                       ['project_id'], ['id']) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:27,代码来源:161f8aceb687_fill_project_id_to_secrets_where_missing.py

示例4: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'order_plugin_metadata')
    if not table_exists:
        op.create_table(
            'order_plugin_metadata',
            sa.Column('id', sa.String(length=36), nullable=False),
            sa.Column('created_at', sa.DateTime(), nullable=False),
            sa.Column('updated_at', sa.DateTime(), nullable=False),
            sa.Column('deleted_at', sa.DateTime(), nullable=True),
            sa.Column('deleted', sa.Boolean(), nullable=False),
            sa.Column('status', sa.String(length=20), nullable=False),
            sa.Column('order_id', sa.String(length=36), nullable=False),
            sa.Column('key', sa.String(length=255), nullable=False),
            sa.Column('value', sa.String(length=255), nullable=False),
            sa.ForeignKeyConstraint(['order_id'], ['orders.id'],),
            sa.PrimaryKeyConstraint('id'),
        ) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:21,代码来源:4070806f6972_add_orders_plugin_metadata_table_and_.py

示例5: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'secret_user_metadata')
    if not table_exists:
        op.create_table(
            'secret_user_metadata',
            sa.Column('id', sa.String(length=36), nullable=False),
            sa.Column('created_at', sa.DateTime(), nullable=False),
            sa.Column('updated_at', sa.DateTime(), nullable=False),
            sa.Column('deleted_at', sa.DateTime(), nullable=True),
            sa.Column('deleted', sa.Boolean(), nullable=False),
            sa.Column('status', sa.String(length=20), nullable=False),
            sa.Column('key', sa.String(length=255), nullable=False),
            sa.Column('value', sa.String(length=255), nullable=False),
            sa.Column('secret_id', sa.String(length=36), nullable=False),
            sa.ForeignKeyConstraint(['secret_id'], ['secrets.id'],),
            sa.PrimaryKeyConstraint('id'),
            sa.UniqueConstraint('secret_id', 'key',
                                name='_secret_key_uc')
        ) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:23,代码来源:dce488646127_add_secret_user_metadata.py

示例6: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'secret_store_metadata')
    if not table_exists:
        op.create_table(
            'secret_store_metadata',
            sa.Column('id', sa.String(length=36), nullable=False),
            sa.Column('created_at', sa.DateTime(), nullable=False),
            sa.Column('updated_at', sa.DateTime(), nullable=False),
            sa.Column('deleted_at', sa.DateTime(), nullable=True),
            sa.Column('deleted', sa.Boolean(), nullable=False),
            sa.Column('status', sa.String(length=20), nullable=False),
            sa.Column('secret_id', sa.String(length=36), nullable=False),
            sa.Column('key', sa.String(length=255), nullable=False),
            sa.Column('value', sa.String(length=255), nullable=False),
            sa.ForeignKeyConstraint(['secret_id'], ['secrets.id'],),
            sa.PrimaryKeyConstraint('id'),
        ) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:21,代码来源:13d127569afa_create_secret_store_metadata_table.py

示例7: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'order_barbican_metadata')
    if not table_exists:
        op.create_table(
            'order_barbican_metadata',
            sa.Column('id', sa.String(length=36), nullable=False),
            sa.Column('created_at', sa.DateTime(), nullable=False),
            sa.Column('updated_at', sa.DateTime(), nullable=False),
            sa.Column('deleted_at', sa.DateTime(), nullable=True),
            sa.Column('deleted', sa.Boolean(), nullable=False),
            sa.Column('status', sa.String(length=20), nullable=False),
            sa.Column('order_id', sa.String(length=36), nullable=False),
            sa.Column('key', sa.String(length=255), nullable=False),
            sa.Column('value', sa.String(length=255), nullable=False),
            sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
            sa.PrimaryKeyConstraint('id')
        ) 
开发者ID:openstack,项目名称:barbican,代码行数:21,代码来源:3d36a26b88af_add_order_barbican_metadata_table.py

示例8: upgrade

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

    # Get relevant tables
    secrets = metadata.tables['secrets']
    project_secret = metadata.tables['project_secret']

    # Add project_id to the secrets
    op.execute(secrets.update().
               values({'project_id': project_secret.c.project_id}).
               where(secrets.c.id == project_secret.c.secret_id).
               where(secrets.c.project_id == None)  # noqa
               )

    # Need to drop foreign key constraint before mysql will allow changes
    ctx = op.get_context()
    _drop_constraint(ctx, 'secrets_project_fk', 'secrets')

    # make project_id no longer nullable
    op.alter_column('secrets', 'project_id',
                    type_=sa.String(36), nullable=False)

    # Create foreign key constraint again
    _create_constraint(ctx, 'secrets_project_fk', 'secrets', 'projects',
                       ['project_id'], ['id']) 
开发者ID:openstack,项目名称:barbican,代码行数:27,代码来源:161f8aceb687_fill_project_id_to_secrets_where_missing.py

示例9: table_has_column

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def table_has_column(table, column):
    config = op.get_context().config
    engine = engine_from_config(
        config.get_section(config.config_ini_section), prefix='sqlalchemy.')
    insp = reflection.Inspector.from_engine(engine)
    has_column = False
    for col in insp.get_columns(table):
        if column not in col['name']:
            continue
        has_column = True
    return has_column 
开发者ID:talkpython,项目名称:data-driven-web-apps-with-pyramid-and-sqlalchemy,代码行数:13,代码来源:alembic_helpers.py

示例10: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def downgrade():
    op.drop_column(SG_TABLE_NAME, ATTR_NAME)
    context = op.get_context()
    if context.bind.dialect.name == 'postgresql':
        op.execute('DROP TYPE %s' % ATTR_NAME) 
开发者ID:openstack,项目名称:manila,代码行数:7,代码来源:d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py

示例11: upgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def upgrade():
    bind = op.get_context().bind
    inspector = reflection.Inspector.from_engine(bind)
    has_tables = inspector.get_table_names()
    if 'event_logs' in has_tables:
        columns = [x.get('name') for x in inspector.get_columns('event_logs')]
        if 'step_key' not in columns:
            op.add_column('event_logs', sa.Column('step_key', sa.String)) 
开发者ID:dagster-io,项目名称:dagster,代码行数:10,代码来源:1ebdd7a9686f_add_step_key_pipeline_name.py

示例12: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def downgrade():
    bind = op.get_context().bind
    inspector = reflection.Inspector.from_engine(bind)
    has_tables = inspector.get_table_names()
    if 'event_logs' in has_tables:
        columns = [x.get('name') for x in inspector.get_columns('event_logs')]
        if 'step_key' in columns:
            op.drop_column('event_logs', 'step_key') 
开发者ID:dagster-io,项目名称:dagster,代码行数:10,代码来源:1ebdd7a9686f_add_step_key_pipeline_name.py

示例13: upgrade

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

    if 'runs' in has_tables and 'run_tags' in has_tables:
        op.drop_constraint('run_tags_run_id_fkey', table_name='run_tags', type='foreignkey')
        op.create_foreign_key(
            'run_tags_run_id_fkey',
            source_table='run_tags',
            referent_table='runs',
            local_cols=['run_id'],
            remote_cols=['run_id'],
            ondelete='CASCADE',
        ) 
开发者ID:dagster-io,项目名称:dagster,代码行数:17,代码来源:8f8dba68fd3b_cascade_run_deletion.py

示例14: downgrade

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

    if 'runs' in has_tables and 'run_tags' in has_tables:
        op.drop_constraint('run_tags_run_id_fkey', table_name='run_tags', type='foreignkey')
        op.create_foreign_key(
            'run_tags_run_id_fkey',
            source_table='run_tags',
            referent_table='runs',
            local_cols=['run_id'],
            remote_cols=['run_id'],
        ) 
开发者ID:dagster-io,项目名称:dagster,代码行数:16,代码来源:8f8dba68fd3b_cascade_run_deletion.py

示例15: downgrade

# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import get_context [as 别名]
def downgrade():
    bind = op.get_context().bind
    inspector = reflection.Inspector.from_engine(bind)
    has_tables = inspector.get_table_names()
    if 'event_logs' in has_tables:
        columns = [x.get('name') for x in inspector.get_columns('event_logs')]
        if 'asset_key' in columns:
            op.drop_column('event_logs', 'asset_key')
            op.drop_index('idx_asset_key', 'event_logs')

            # also drop the index that was missing from the step_key migration
            op.drop_index('idx_step_key', 'event_logs') 
开发者ID:dagster-io,项目名称:dagster,代码行数:14,代码来源:727ffe943a9f_add_asset_key.py


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