本文整理汇总了Python中alembic.context.get_context方法的典型用法代码示例。如果您正苦于以下问题:Python context.get_context方法的具体用法?Python context.get_context怎么用?Python context.get_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.context
的用法示例。
在下文中一共展示了context.get_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
if context.get_context().dialect.name in ['oracle', 'postgresql']:
drop_constraint('REQUESTS_STATE_CHK', 'requests', type_='check')
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5:
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8:
op.execute('ALTER TABLE ' + schema + 'requests DROP CHECK REQUESTS_STATE_CHK') # pylint: disable=no-member
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W', 'M')")
示例2: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
if context.get_context().dialect.name == 'oracle':
drop_constraint('REQUESTS_STATE_CHK', 'requests', type_='check')
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W')")
elif context.get_context().dialect.name == 'postgresql':
op.execute('ALTER TABLE ' + schema + 'requests DROP CONSTRAINT IF EXISTS "REQUESTS_STATE_CHK", ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5:
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8:
op.execute('ALTER TABLE ' + schema + 'requests DROP CHECK REQUESTS_STATE_CHK') # pylint: disable=no-member
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U', 'W')")
示例3: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
if context.get_context().dialect.name == 'oracle':
drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
drop_table('collection_replicas')
elif context.get_context().dialect.name == 'postgresql':
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
op.execute('ALTER TABLE ' + schema + 'collection_replicas ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member
drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
drop_table('collection_replicas')
elif context.get_context().dialect.name == 'mysql':
drop_table('collection_replicas')
示例4: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
if context.get_context().dialect.name in ['oracle', 'postgresql']:
drop_column('collection_replicas', 'available_replicas_cnt', schema=schema)
drop_column('collection_replicas', 'available_bytes', schema=schema)
drop_table('updated_col_rep')
elif context.get_context().dialect.name == 'mysql':
drop_column('collection_replicas', 'available_replicas_cnt', schema=schema)
drop_column('collection_replicas', 'available_bytes', schema=schema)
drop_constraint('UPDATED_COL_REP_PK', 'updated_col_rep', type_='primary')
drop_index('UPDATED_COL_REP_SNR_IDX', 'updated_col_rep')
drop_table('updated_col_rep')
示例5: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
if context.get_context().dialect.name in ['oracle', 'postgresql']:
drop_constraint('SOURCES_REPLICA_FK', 'sources', type_='foreignkey')
drop_constraint('REPLICAS_PK', 'replicas', type_='primary')
create_primary_key('REPLICAS_PK', 'replicas', ['scope', 'name', 'rse_id'])
create_foreign_key('SOURCES_REPLICA_FK', 'sources', 'replicas', ['scope', 'name', 'rse_id'], ['scope', 'name', 'rse_id'])
elif context.get_context().dialect.name == 'mysql':
drop_constraint('SOURCES_REPLICA_FK', 'sources', type_='foreignkey')
# The constraint has an internal index which is not automatically dropped,
# we have to do that manually
drop_index('SOURCES_REPLICA_FK', 'sources')
drop_constraint(constraint_name='REPLICAS_LFN_FK', table_name='replicas', type_='foreignkey')
drop_constraint(constraint_name='REPLICAS_RSE_ID_FK', table_name='replicas', type_='foreignkey')
drop_constraint('REPLICAS_PK', 'replicas', type_='primary')
create_foreign_key('REPLICAS_LFN_FK', 'replicas', 'dids', ['scope', 'name'], ['scope', 'name'])
create_foreign_key('REPLICAS_RSE_ID_FK', 'replicas', 'rses', ['rse_id'], ['id'])
create_primary_key('REPLICAS_PK', 'replicas', ['scope', 'name', 'rse_id'])
create_foreign_key('SOURCES_REPLICA_FK', 'sources', 'replicas', ['scope', 'name', 'rse_id'], ['scope', 'name', 'rse_id'])
示例6: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
if context.get_context().dialect.name in ['oracle', 'postgresql']:
drop_constraint(constraint_name='SOURCES_REPLICA_FK', table_name='sources', type_='foreignkey')
drop_constraint(constraint_name='REPLICAS_PK', table_name='replicas', type_='primary')
create_primary_key('REPLICAS_PK', 'replicas', ['rse_id', 'scope', 'name'])
create_foreign_key('SOURCES_REPLICA_FK', 'sources', 'replicas', ['rse_id', 'scope', 'name'], ['rse_id', 'scope', 'name'])
elif context.get_context().dialect.name == 'mysql':
drop_constraint(constraint_name='SOURCES_REPLICA_FK', table_name='sources', type_='foreignkey')
# The constraint has an internal index which is not automatically dropped,
# we have to do that manually
drop_index('SOURCES_REPLICA_FK', 'sources')
drop_constraint(constraint_name='REPLICAS_LFN_FK', table_name='replicas', type_='foreignkey')
drop_constraint(constraint_name='REPLICAS_RSE_ID_FK', table_name='replicas', type_='foreignkey')
drop_constraint(constraint_name='REPLICAS_PK', table_name='replicas', type_='primary')
create_foreign_key('REPLICAS_LFN_FK', 'replicas', 'dids', ['scope', 'name'], ['scope', 'name'])
create_foreign_key('REPLICAS_RSE_ID_FK', 'replicas', 'rses', ['rse_id'], ['id'])
create_primary_key('REPLICAS_PK', 'replicas', ['rse_id', 'scope', 'name'])
create_foreign_key('SOURCES_REPLICA_FK', 'sources', 'replicas', ['rse_id', 'scope', 'name'], ['rse_id', 'scope', 'name'])
示例7: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
create_table('lifetime_except',
sa.Column('id', GUID()),
sa.Column('scope', sa.String(25)),
sa.Column('name', sa.String(255)),
sa.Column('did_type', DIDType.db_type()),
sa.Column('account', sa.String(25)),
sa.Column('comments', sa.String(4000)),
sa.Column('pattern', sa.String(255)),
sa.Column('state', LifetimeExceptionsState.db_type()),
sa.Column('created_at', sa.DateTime, default=datetime.datetime.utcnow),
sa.Column('updated_at', sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow),
sa.Column('expires_at', sa.DateTime))
create_primary_key('LIFETIME_EXCEPT_PK', 'lifetime_except', ['id', 'scope', 'name', 'did_type', 'account'])
create_check_constraint('LIFETIME_EXCEPT_SCOPE_NN', 'lifetime_except', 'scope is not null')
create_check_constraint('LIFETIME_EXCEPT_NAME_NN', 'lifetime_except', 'name is not null')
create_check_constraint('LIFETIME_EXCEPT_DID_TYPE_NN', 'lifetime_except', 'did_type is not null')
示例8: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
if context.get_context().dialect.name == 'oracle':
add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False))
drop_constraint('RULES_STATE_CHK', 'rules')
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
elif context.get_context().dialect.name == 'postgresql':
add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1])
drop_constraint('RULES_STATE_CHK', 'rules')
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5:
add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1])
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8:
add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema[:-1])
op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_STATE_CHK') # pylint: disable=no-member
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
示例9: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
if context.get_context().dialect.name == 'oracle':
drop_column('rules', 'ignore_account_limit')
drop_constraint('RULES_STATE_CHK', 'rules')
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
elif context.get_context().dialect.name == 'postgresql':
drop_column('rules', 'ignore_account_limit', schema=schema[:-1])
op.execute('ALTER TABLE ' + schema + 'rules DROP CONSTRAINT IF EXISTS "RULES_STATE_CHK", ALTER COLUMN state TYPE CHAR') # pylint: disable=no-member
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5:
drop_column('rules', 'ignore_account_limit', schema=schema[:-1])
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8:
drop_column('rules', 'ignore_account_limit', schema=schema[:-1])
op.execute('ALTER TABLE ' + schema + 'rules DROP CHECK RULES_STATE_CHK') # pylint: disable=no-member
create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
示例10: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
if context.get_context().dialect.name in ['oracle', 'postgresql']:
drop_constraint('REQUESTS_STATE_CHK', 'requests', type_='check')
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 5:
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')")
elif context.get_context().dialect.name == 'mysql' and context.get_context().dialect.server_version_info[0] == 8:
op.execute('ALTER TABLE ' + schema + 'requests DROP CHECK REQUESTS_STATE_CHK') # pylint: disable=no-member
create_check_constraint(constraint_name='REQUESTS_STATE_CHK', table_name='requests',
condition="state in ('Q', 'G', 'S', 'D', 'F', 'L', 'N', 'O', 'A', 'U')")
示例11: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
# CONTENTS_HISTORY
drop_constraint('CONTENTS_HIST_PK', 'contents_history', type_='primary')
# ARCHIVE_CONTENTS_HISTORY
drop_constraint(constraint_name='ARCH_CONT_HIST_PK', table_name='archive_contents_history', type_='primary')
# RULES_HIST_RECENT
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
drop_constraint(constraint_name='RULES_HIST_RECENT_PK', table_name='rules_hist_recent', type_='primary')
drop_column('rules_hist_recent', 'history_id', schema=schema)
# RULES_HISTORY
drop_column('rules_history', 'history_id', schema=schema)
示例12: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
# CONTENTS_HISTORY
create_primary_key('CONTENTS_HIST_PK', 'contents_history', ['scope', 'name', 'child_scope', 'child_name'])
# ARCHIVE_CONTENTS_HISTORY
create_primary_key('ARCH_CONT_HIST_PK', 'archive_contents_history', ['scope', 'name', 'child_scope', 'child_name'])
drop_index('ARCH_CONT_HIST_IDX', 'archive_contents_history')
# RULES_HIST_RECENT
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
add_column('rules_hist_recent', sa.Column('history_id', GUID()), schema=schema)
create_primary_key('RULES_HIST_RECENT_PK', 'rules_hist_recent', ['history_id'])
# RULES_HISTORY
add_column('rules_history', sa.Column('history_id', GUID()), schema=schema)
create_primary_key('RULES_HIST_LONGTERM_PK', 'rules_history', ['history_id'])
# MESSAGES_HISTORY
create_primary_key('MESSAGES_HIST_ID_PK', 'messages_history', ['id'])
示例13: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
drop_table('account_attr_map')
elif context.get_context().dialect.name == 'postgresql':
# drop_constraint('ACCOUNT_ATTR_MAP_PK', 'account_attr_map', type_='primary')
# drop_constraint('ACCOUNT_ATTR_MAP_CREATED_NN', 'account_attr_map')
# drop_constraint('ACCOUNT_ATTR_MAP_UPDATED_NN', 'account_attr_map')
# drop_constraint('ACCOUNT_ATTR_MAP_ACCOUNT_FK', 'account_attr_map')
# drop_index('ACCOUNT_ATTR_MAP_KEY_VALUE_IDX', 'account_attr_map')
# drop_table('account_attr_map')
pass
示例14: upgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def upgrade():
'''
Upgrade the database to this revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
drop_index('HEARTBEATS_UPDATED_AT', 'heartbeats')
add_column('heartbeats', sa.Column('payload', String(3000)), schema=schema)
示例15: downgrade
# 需要导入模块: from alembic import context [as 别名]
# 或者: from alembic.context import get_context [as 别名]
def downgrade():
'''
Downgrade the database to the previous revision
'''
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
create_index('HEARTBEATS_UPDATED_AT', 'heartbeats', ['updated_at'])
drop_column('heartbeats', 'payload', schema=schema)