Python alembic.op.get_context() Examples

The following are 30 code examples of alembic.op.get_context(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module alembic.op , or try the search function .
Example #1
Source File: 13d127569afa_create_secret_store_metadata_table.py    From barbican with Apache License 2.0 6 votes vote down vote up
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'),
        ) 
Example #2
Source File: dce488646127_add_secret_user_metadata.py    From barbican with Apache License 2.0 6 votes vote down vote up
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')
        ) 
Example #3
Source File: 4070806f6972_add_orders_plugin_metadata_table_and_.py    From barbican with Apache License 2.0 6 votes vote down vote up
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'),
        ) 
Example #4
Source File: 13d127569afa_create_secret_store_metadata_table.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
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'),
        ) 
Example #5
Source File: 161f8aceb687_fill_project_id_to_secrets_where_missing.py    From barbican with Apache License 2.0 6 votes vote down vote up
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']) 
Example #6
Source File: 3d36a26b88af_add_order_barbican_metadata_table.py    From barbican with Apache License 2.0 6 votes vote down vote up
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')
        ) 
Example #7
Source File: dce488646127_add_secret_user_metadata.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
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')
        ) 
Example #8
Source File: d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py    From manila with Apache License 2.0 6 votes vote down vote up
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,
        ),
    ) 
Example #9
Source File: 4070806f6972_add_orders_plugin_metadata_table_and_.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
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'),
        ) 
Example #10
Source File: 161f8aceb687_fill_project_id_to_secrets_where_missing.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
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']) 
Example #11
Source File: 6a4457517a3_rename_acl_creator_only_to_project_.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
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}) 
Example #12
Source File: alembic_helpers.py    From data-driven-web-apps-with-flask with MIT License 5 votes vote down vote up
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 
Example #13
Source File: 46b98cde536_add_project_quotas_table.py    From barbican with Apache License 2.0 5 votes vote down vote up
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'project_quotas')
    if not table_exists:
        op.create_table(
            'project_quotas',
            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('project_id', sa.String(length=36), nullable=False),
            sa.Column('secrets', sa.Integer(), nullable=True),
            sa.Column('orders', sa.Integer(), nullable=True),
            sa.Column('containers', sa.Integer(), nullable=True),
            sa.Column('transport_keys', sa.Integer(), nullable=True),
            sa.Column('consumers', sa.Integer(), nullable=True),
            sa.ForeignKeyConstraint(['project_id'],
                                    ['projects.id'],
                                    name='project_quotas_fk'),
            sa.PrimaryKeyConstraint('id'),
            mysql_engine='InnoDB')
        op.create_index(
            op.f('ix_project_quotas_project_id'),
            'project_quotas',
            ['project_id'],
            unique=False) 
Example #14
Source File: alembic_helpers.py    From GeoHealthCheck with MIT License 5 votes vote down vote up
def get_table_names():
    config = op.get_context().config
    engine = engine_from_config(
        config.get_section(config.config_ini_section), prefix='sqlalchemy.')
    insp = reflection.Inspector.from_engine(engine)
    return insp.get_table_names()


# Check if list of table names in database 
Example #15
Source File: f8c799db4aa0_fix_unnamed_constraints.py    From cloudkitty with Apache License 2.0 5 votes vote down vote up
def upgrade():
    dialect = op.get_context().dialect
    if dialect.name == 'sqlite':
        upgrade_sqlite()
    elif dialect.name == 'mysql':
        upgrade_mysql()
    elif dialect.name == 'postgresql':
        upgrade_postgresql() 
Example #16
Source File: 4fa888fd7eda_added_threshold_support.py    From cloudkitty with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # NOTE(sheeprine): Hack to let the migrations pass for postgresql
    dialect = op.get_context().dialect.name
    if dialect == 'postgresql':
        constraints = ['uniq_field_threshold', 'uniq_service_threshold']
    else:
        constraints = ['uniq_field_mapping', 'uniq_service_mapping']
    op.create_table(
        'hashmap_thresholds',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('threshold_id', sa.String(length=36), nullable=False),
        sa.Column('level', sa.Numeric(precision=20, scale=8), nullable=True),
        sa.Column('cost', sa.Numeric(precision=20, scale=8), nullable=False),
        sa.Column(
            'map_type',
            sa.Enum('flat', 'rate', name='enum_map_type'),
            nullable=False),
        sa.Column('service_id', sa.Integer(), nullable=True),
        sa.Column('field_id', sa.Integer(), nullable=True),
        sa.Column('group_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['field_id'],
            ['hashmap_fields.id'],
            ondelete='CASCADE'),
        sa.ForeignKeyConstraint(
            ['group_id'],
            ['hashmap_groups.id'],
            ondelete='SET NULL'),
        sa.ForeignKeyConstraint(
            ['service_id'],
            ['hashmap_services.id'],
            ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('threshold_id'),
        sa.UniqueConstraint('level', 'field_id', name=constraints[0]),
        sa.UniqueConstraint('level', 'service_id', name=constraints[1]),
        mysql_charset='utf8',
        mysql_engine='InnoDB') 
Example #17
Source File: alembic_helpers.py    From GeoHealthCheck with MIT License 5 votes vote down vote up
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


# Get list of table names from database 
Example #18
Source File: 0f8c192a061f_add_secret_consumers.py    From barbican with Apache License 2.0 5 votes vote down vote up
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine,
                                         "secret_consumer_metadata")
    if not table_exists:
        op.create_table(
            "secret_consumer_metadata",
            # ModelBase
            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),
            # SecretConsumerMetadatum
            sa.Column("secret_id", sa.String(36), nullable=False),
            sa.Column("project_id", sa.String(36), nullable=False),
            sa.Column("service", sa.String(255), nullable=False),
            sa.Column("resource_type", sa.String(255), nullable=False),
            sa.Column("resource_id", sa.String(36), nullable=False),
            # Constraints and Indexes
            sa.PrimaryKeyConstraint("id"),
            sa.ForeignKeyConstraint(["secret_id"], ["secrets.id"]),
            sa.UniqueConstraint(
                "secret_id", "resource_id", name="_secret_consumer_resource_uc"
            ),
            sa.Index("ix_secret_consumer_metadata_secret_id", "secret_id"),
            sa.Index("ix_secret_consumer_metadata_resource_id", "resource_id"),
        ) 
Example #19
Source File: 61e52d26ebea_message_blacklist.py    From pushkin with MIT License 5 votes vote down vote up
def upgrade():
    context = op.get_context()
    connection = op.get_bind()

    op.create_table('message_blacklist',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('login_id', sa.BigInteger(), nullable=False),
        sa.Column('blacklist', postgresql.ARRAY(sa.Integer)),
        sa.ForeignKeyConstraint(['login_id'], ['login.id'], ondelete='CASCADE', name="ref_message_blacklist_login_id_to_login"),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('idx_message_blacklist_login_id'), 'message_blacklist', ['login_id'], unique=True) 
Example #20
Source File: alembic_helpers.py    From data-driven-web-apps-with-flask with MIT License 5 votes vote down vote up
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 
Example #21
Source File: alembic_helpers.py    From data-driven-web-apps-with-flask with MIT License 5 votes vote down vote up
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 
Example #22
Source File: alembic_helpers.py    From data-driven-web-apps-with-flask with MIT License 5 votes vote down vote up
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 
Example #23
Source File: 1c0f328bfce0_fixing_composite_primary_keys_and_.py    From sgx-kms with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_index(op.f('ix_certificate_authority_metadata_ca_id'), 'certificate_authority_metadata', ['ca_id'], unique=False)
    op.create_index(op.f('ix_certificate_authority_metadata_key'), 'certificate_authority_metadata', ['key'], unique=False)
    op.create_index(op.f('ix_container_consumer_metadata_container_id'), 'container_consumer_metadata', ['container_id'], unique=False)
    op.create_index(op.f('ix_container_secret_container_id'), 'container_secret', ['container_id'], unique=False)
    op.create_index(op.f('ix_container_secret_secret_id'), 'container_secret', ['secret_id'], unique=False)
    op.create_index(op.f('ix_containers_project_id'), 'containers', ['project_id'], unique=False)
    op.create_index(op.f('ix_encrypted_data_kek_id'), 'encrypted_data', ['kek_id'], unique=False)
    op.create_index(op.f('ix_encrypted_data_secret_id'), 'encrypted_data', ['secret_id'], unique=False)
    op.create_index(op.f('ix_kek_data_project_id'), 'kek_data', ['project_id'], unique=False)
    op.create_index(op.f('ix_order_barbican_metadata_order_id'), 'order_barbican_metadata', ['order_id'], unique=False)
    op.create_index(op.f('ix_order_plugin_metadata_order_id'), 'order_plugin_metadata', ['order_id'], unique=False)
    op.create_index(op.f('ix_order_retry_tasks_order_id'), 'order_retry_tasks', ['order_id'], unique=False)
    op.create_index(op.f('ix_orders_container_id'), 'orders', ['container_id'], unique=False)
    op.create_index(op.f('ix_orders_project_id'), 'orders', ['project_id'], unique=False)
    op.create_index(op.f('ix_orders_secret_id'), 'orders', ['secret_id'], unique=False)

    ctx = op.get_context()
    _drop_constraint(ctx, 'preferred_certificate_authorities_ibfk_1', 'preferred_certificate_authorities')

    op.alter_column('preferred_certificate_authorities', 'ca_id',
               existing_type=sa.VARCHAR(length=36),
               nullable=False)

    op.create_foreign_key('preferred_certificate_authorities_fk', 'preferred_certificate_authorities',
                          'certificate_authorities', ['ca_id'], ['id'])

    op.create_index(op.f('ix_preferred_certificate_authorities_ca_id'), 'preferred_certificate_authorities', ['ca_id'], unique=False)
    op.create_index(op.f('ix_preferred_certificate_authorities_project_id'), 'preferred_certificate_authorities', ['project_id'], unique=True)
    op.create_index(op.f('ix_project_certificate_authorities_ca_id'), 'project_certificate_authorities', ['ca_id'], unique=False)
    op.create_index(op.f('ix_project_certificate_authorities_project_id'), 'project_certificate_authorities', ['project_id'], unique=False)
    op.create_index(op.f('ix_project_secret_project_id'), 'project_secret', ['project_id'], unique=False)
    op.create_index(op.f('ix_project_secret_secret_id'), 'project_secret', ['secret_id'], unique=False)
    op.create_index(op.f('ix_secret_store_metadata_secret_id'), 'secret_store_metadata', ['secret_id'], unique=False) 
Example #24
Source File: 46b98cde536_add_project_quotas_table.py    From sgx-kms with Apache License 2.0 5 votes vote down vote up
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()
    table_exists = ctx.dialect.has_table(con.engine, 'project_quotas')
    if not table_exists:
        op.create_table(
            'project_quotas',
            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('project_id', sa.String(length=36), nullable=False),
            sa.Column('secrets', sa.Integer(), nullable=True),
            sa.Column('orders', sa.Integer(), nullable=True),
            sa.Column('containers', sa.Integer(), nullable=True),
            sa.Column('transport_keys', sa.Integer(), nullable=True),
            sa.Column('consumers', sa.Integer(), nullable=True),
            sa.ForeignKeyConstraint(['project_id'],
                                    ['projects.id'],
                                    name='project_quotas_fk'),
            sa.PrimaryKeyConstraint('id'),
            mysql_engine='InnoDB')
        op.create_index(
            op.f('ix_project_quotas_project_id'),
            'project_quotas',
            ['project_id'],
            unique=False) 
Example #25
Source File: ea6934da4b17_add_encryption_keys_policies_table.py    From sgx-kms with Apache License 2.0 5 votes vote down vote up
def downgrade():
    ctx = op.get_context()
    con = op.get_bind()

    table_exists = ctx.dialect.has_table(con.engine, 'encryption_keys')
    if table_exists:
        op.drop_table('encryption_keys')

    table_exists = ctx.dialect.has_table(con.engine, 'project_policies')
    if table_exists:
        op.drop_table('project_policies') 
Example #26
Source File: ea6934da4b17_add_encryption_keys_policies_table.py    From sgx-kms with Apache License 2.0 5 votes vote down vote up
def upgrade():
    ctx = op.get_context()
    con = op.get_bind()

    table_exists = ctx.dialect.has_table(con.engine, 'encryption_keys')
    if not table_exists:
        op.create_table(
            'encryption_keys',
            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('project_id', sa.String(length=36), nullable=False),
            sa.Column('session_key', sa.Text()),
            sa.Column('master_key', sa.Text()),
            sa.ForeignKeyConstraint(['project_id'], ['projects.id']),
            sa.PrimaryKeyConstraint('id')
        )

    table_exists = ctx.dialect.has_table(con.engine, 'project_policies')
    if not table_exists:
        op.create_table(
            'project_policies',
            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('project_id', sa.String(length=36), nullable=False),
            sa.Column('mr_s', sa.Text()),
            sa.Column('mr_e', sa.Text()),
            sa.Column('mr_e_list', sa.Text()),
            sa.Column('policy', sa.Integer()),
            sa.ForeignKeyConstraint(['project_id'], ['projects.id']),
            sa.PrimaryKeyConstraint('id')
        ) 
Example #27
Source File: utils.py    From dagster with Apache License 2.0 5 votes vote down vote up
def get_inspector():
    # pylint: disable=no-member
    bind = op.get_context().bind
    return reflection.Inspector.from_engine(bind) 
Example #28
Source File: 3b1e175a2be3_add_step_key_pipeline_name.py    From dagster with Apache License 2.0 5 votes vote down vote up
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:
        op.drop_column('event_logs', 'step_key') 
Example #29
Source File: 3b1e175a2be3_add_step_key_pipeline_name.py    From dagster with Apache License 2.0 5 votes vote down vote up
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:
        op.add_column('event_logs', sa.Column('step_key', sa.String)) 
Example #30
Source File: alembic_helpers.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
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