本文整理汇总了Python中alembic.op.execute方法的典型用法代码示例。如果您正苦于以下问题:Python op.execute方法的具体用法?Python op.execute怎么用?Python op.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.op
的用法示例。
在下文中一共展示了op.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
op.rename_table('use_of_force_incidents', 'use_of_force_incidents_impd')
op.execute('ALTER SEQUENCE use_of_force_incidents_id_seq RENAME TO use_of_force_incidents_impd_id_seq')
op.execute('ALTER INDEX use_of_force_incidents_pkey RENAME TO use_of_force_incidents_impd_pkey')
op.execute('ALTER TABLE use_of_force_incidents_impd RENAME CONSTRAINT "use_of_force_incidents_department_id_fkey" TO "use_of_force_incidents_impd_department_id_fkey"')
op.rename_table('citizen_complaints', 'citizen_complaints_impd')
op.execute('ALTER SEQUENCE citizen_complaints_id_seq RENAME TO citizen_complaints_impd_id_seq')
op.execute('ALTER INDEX citizen_complaints_pkey RENAME TO citizen_complaints_impd_pkey')
op.execute('ALTER TABLE citizen_complaints_impd RENAME CONSTRAINT "citizen_complaints_department_id_fkey" TO "citizen_complaints_impd_department_id_fkey"')
op.rename_table('assaults_on_officers', 'assaults_on_officers_impd')
op.execute('ALTER SEQUENCE assaults_on_officers_id_seq RENAME TO assaults_on_officers_impd_id_seq')
op.execute('ALTER INDEX assaults_on_officers_pkey RENAME TO assaults_on_officers_impd_pkey')
op.execute('ALTER TABLE assaults_on_officers_impd RENAME CONSTRAINT "assaults_on_officers_department_id_fkey" TO "assaults_on_officers_impd_department_id_fkey"')
op.rename_table('officer_involved_shootings', 'officer_involved_shootings_impd')
op.execute('ALTER SEQUENCE officer_involved_shootings_id_seq RENAME TO officer_involved_shootings_impd_id_seq')
op.execute('ALTER INDEX officer_involved_shootings_pkey RENAME TO officer_involved_shootings_impd_pkey')
op.execute('ALTER TABLE officer_involved_shootings_impd RENAME CONSTRAINT "officer_involved_shootings_department_id_fkey" TO "officer_involved_shootings_impd_department_id_fkey"')
示例2: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def downgrade():
op.rename_table('use_of_force_incidents_impd', 'use_of_force_incidents')
op.execute('ALTER SEQUENCE use_of_force_incidents_impd_id_seq RENAME TO use_of_force_incidents_id_seq')
op.execute('ALTER INDEX use_of_force_incidents_impd_pkey RENAME TO use_of_force_incidents_pkey')
op.execute('ALTER TABLE use_of_force_incidents RENAME CONSTRAINT "use_of_force_incidents_impd_department_id_fkey" TO "use_of_force_incidents_department_id_fkey"')
op.rename_table('citizen_complaints_impd', 'citizen_complaints')
op.execute('ALTER SEQUENCE citizen_complaints_impd_id_seq RENAME TO citizen_complaints_id_seq')
op.execute('ALTER INDEX citizen_complaints_impd_pkey RENAME TO citizen_complaints_pkey')
op.execute('ALTER TABLE citizen_complaints RENAME CONSTRAINT "citizen_complaints_impd_department_id_fkey" TO "citizen_complaints_department_id_fkey"')
op.rename_table('assaults_on_officers_impd', 'assaults_on_officers')
op.execute('ALTER SEQUENCE assaults_on_officers_impd_id_seq RENAME TO assaults_on_officers_id_seq')
op.execute('ALTER INDEX assaults_on_officers_impd_pkey RENAME TO assaults_on_officers_pkey')
op.execute('ALTER TABLE assaults_on_officers RENAME CONSTRAINT "assaults_on_officers_impd_department_id_fkey" TO "assaults_on_officers_department_id_fkey"')
op.rename_table('officer_involved_shootings_impd', 'officer_involved_shootings')
op.execute('ALTER SEQUENCE officer_involved_shootings_impd_id_seq RENAME TO officer_involved_shootings_id_seq')
op.execute('ALTER INDEX officer_involved_shootings_impd_pkey RENAME TO officer_involved_shootings_pkey')
op.execute('ALTER TABLE officer_involved_shootings RENAME CONSTRAINT "officer_involved_shootings_impd_department_id_fkey" TO "officer_involved_shootings_department_id_fkey"')
示例3: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
for table_name in ("resource", "resource_history", "metric"):
creator_col = sa.Column("creator", sa.String(255))
created_by_user_id_col = sa.Column("created_by_user_id",
sa.String(255))
created_by_project_id_col = sa.Column("created_by_project_id",
sa.String(255))
op.add_column(table_name, creator_col)
t = sa.sql.table(
table_name, creator_col,
created_by_user_id_col, created_by_project_id_col)
op.execute(
t.update().values(
creator=(
created_by_user_id_col + ":" + created_by_project_id_col
)).where((created_by_user_id_col is not None)
| (created_by_project_id_col is not None)))
op.drop_column(table_name, "created_by_user_id")
op.drop_column(table_name, "created_by_project_id")
示例4: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
op.add_column("resource_type", sa.Column('tablename', sa.String(18),
nullable=True))
resource_type = sa.Table(
'resource_type', sa.MetaData(),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('tablename', sa.String(18), nullable=True)
)
op.execute(resource_type.update().where(
resource_type.c.name == "instance_network_interface"
).values({'tablename': op.inline_literal("'instance_net_int'")}))
op.execute(resource_type.update().where(
resource_type.c.name != "instance_network_interface"
).values({'tablename': resource_type.c.name}))
op.alter_column("resource_type", "tablename", type_=sa.String(18),
nullable=False)
op.create_unique_constraint("uniq_resource_type0tablename",
"resource_type", ["tablename"])
示例5: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def downgrade():
''' Add the column _close_status to the table projects.
'''
engine = op.get_bind()
Session = sa.orm.scoped_session(sa.orm.sessionmaker())
Session.configure(bind=engine)
session = Session()
statuses = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
for status in statuses:
ticket_stat = model.StatusIssue(status=status)
session.add(ticket_stat)
session.commit()
# Set the close_status for all the closed tickets
op.execute('''UPDATE "issues" SET status=close_status where status != 'Open'; ''')
# Remove the old status
op.execute('''DELETE FROM "status_issue" WHERE status = 'Closed'; ''')
op.drop_column('projects', '_close_status')
op.drop_column('issues', 'close_status')
示例6: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
''' Add is_fork column to project table'''
op.add_column(
'projects',
sa.Column(
'is_fork', sa.Boolean,
default=False,
nullable=True)
)
op.execute('''UPDATE "projects" '''
'''SET is_fork=TRUE WHERE parent_id IS NOT NULL;''')
op.execute('''UPDATE "projects" '''
'''SET is_fork=FALSE WHERE parent_id IS NULL;''')
op.alter_column(
'projects', 'is_fork',
nullable=False, existing_nullable=True)
示例7: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
"""
Add new lock types to the lock_type_enum enum.
With this there are three enums:
- WORKER, used to lock action on the main git repo (sources)
- WORKER_TICKET, used to lock actions on the ticket git repo
- WORKER_REQUEST, used to lock actions on the request git repo
"""
# Let's start with commit to close the current transaction
# cf https://bitbucket.org/zzzeek/alembic/issue/123
op.execute('COMMIT')
op.execute(
"ALTER TYPE lock_type_enum ADD VALUE 'WORKER_TICKET';")
op.execute(
"ALTER TYPE lock_type_enum ADD VALUE 'WORKER_REQUEST';")
示例8: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def downgrade():
''' Revert the status column of the pull_requests table.
'''
op.add_column(
'pull_requests',
sa.Column(
'_status', sa.Boolean, default=True, nullable=True)
)
op.execute('''UPDATE "pull_requests" '''
'''SET _status=TRUE WHERE status='Open';''')
op.execute('''UPDATE "pull_requests" '''
'''SET _status=FALSE WHERE status!='Open';''')
op.drop_column('pull_requests', 'status')
op.alter_column(
'pull_requests',
column_name='_status', new_column_name='status',
nullable=False, existing_nullable=True)
示例9: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
''' Add the column updated_on to the table pull_requests.
'''
op.add_column(
'pull_requests',
sa.Column(
'updated_on',
sa.DateTime,
nullable=True,
default=sa.func.now(),
onupdate=sa.func.now()
)
)
op.execute('''UPDATE "pull_requests" SET updated_on=date_created;''')
op.alter_column(
'pull_requests',
column_name='updated_on',
nullable=False,
existing_nullable=True)
示例10: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
""" Add the status column to pull_request_flags and migrate the data.
"""
op.add_column(
'pull_request_flags',
sa.Column('status', sa.String(32), nullable=True)
)
op.execute(
'UPDATE pull_request_flags SET status=\'success\' '
'WHERE percent in (100, \'100\')')
op.execute(
'UPDATE pull_request_flags SET status=\'failure\' '
'WHERE percent not in (100, \'100\')')
op.alter_column(
'pull_request_flags', 'status',
nullable=False, existing_nullable=True)
示例11: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [as 别名]
def upgrade():
''' Add ci_job column to projects table'''
op.add_column(
'hook_pagure_ci',
sa.Column('ci_job', sa.String(255), nullable=True, unique=False)
)
con = op.get_bind()
results = con.execute('SELECT id, ci_url FROM hook_pagure_ci')
for id, url in results:
ci_job = url.split('/job/', 1)[1].split('/', 1)[0]
ci_url = url.split('/job/')[0]
op.execute(
"UPDATE hook_pagure_ci SET ci_job='{}' WHERE id = '{}'".format(ci_job, id))
op.execute(
"UPDATE hook_pagure_ci SET ci_url='{}' WHERE id = '{}'".format(ci_url, id))
op.alter_column(
'hook_pagure_ci', 'ci_job',
nullable=False, existing_nullable=True)
示例12: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [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')")
示例13: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [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')
示例14: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [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')")
示例15: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import execute [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')")