Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def downgrade():
op.drop_constraint(op.f('fk_requests_event_id_events'), 'requests', schema='events')
# Upgrade UserOldId
count = conn.scalar(sa.select([sa.func.count('*')]).select_from(useroldid))
progress = get_progressbar("Old ids", count)
progress.start()
items = conn.execute(sa.select([useroldid.c.userid]))
for counter, item in enumerate(items):
conn.execute(
sa.update(useroldid)
.where(useroldid.c.userid == item.userid)
.values(uuid=buid2uuid(item.userid))
)
progress.update(counter)
progress.finish()
op.drop_constraint('useroldid_pkey', 'useroldid', type_='primary')
op.drop_column('useroldid', 'userid')
op.drop_constraint('useroldid_uuid_key', 'useroldid', type_='unique')
op.alter_column('useroldid', 'uuid', new_column_name='id')
op.create_primary_key('useroldid_pkey', 'useroldid', ['id'])
create_foreign_key('reporthashes_report_id_fkey', 'reporthashes', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reporthistorydaily_report_id_fkey', 'reporthistorydaily', type_='foreignkey')
create_foreign_key('reporthistorydaily_report_id_fkey', 'reporthistorydaily', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reporthistorymonthly_report_id_fkey', 'reporthistorymonthly', type_='foreignkey')
create_foreign_key('reporthistorymonthly_report_id_fkey', 'reporthistorymonthly', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reporthistoryweekly_report_id_fkey', 'reporthistoryweekly', type_='foreignkey')
create_foreign_key('reporthistoryweekly_report_id_fkey', 'reporthistoryweekly', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reportmantis_report_id_fkey', 'reportmantis', type_='foreignkey')
create_foreign_key('reportmantis_report_id_fkey', 'reportmantis', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reportopsysreleases_report_id_fkey', 'reportopsysreleases', type_='foreignkey')
create_foreign_key('reportopsysreleases_report_id_fkey', 'reportopsysreleases', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reportpackages_report_id_fkey', 'reportpackages', type_='foreignkey')
create_foreign_key('reportpackages_report_id_fkey', 'reportpackages', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reportraw_report_id_fkey', 'reportraw', type_='foreignkey')
create_foreign_key('reportraw_report_id_fkey', 'reportraw', 'reports',
['report_id'], ['id'], ondelete='CASCADE')
drop_constraint('reportreasons_report_id_fkey', 'reportreasons', type_='foreignkey')
create_foreign_key('reportbtthreads_backtrace_id_fkey', 'reportbtthreads', 'reportbacktraces',
['backtrace_id'], ['id'])
drop_constraint('reportbthashes_backtrace_id_fkey', 'reportbthashes', type_='foreignkey')
create_foreign_key('reportbthashes_backtrace_id_fkey', 'reportbthashes', 'reportbacktraces',
['backtrace_id'], ['id'])
drop_constraint('reportbtframes_thread_id_fkey', 'reportbtframes', type_='foreignkey')
create_foreign_key('reportbtframes_thread_id_fkey', 'reportbtframes', 'reportbtthreads',
['thread_id'], ['id'])
drop_constraint('reportbttaintflags_backtrace_id_fkey', 'reportbttaintflags', type_='foreignkey')
create_foreign_key('reportbttaintflags_backtrace_id_fkey', 'reportbttaintflags', 'reportbacktraces',
['backtrace_id'], ['id'])
drop_constraint('reportbtkernelmodules_backtrace_id_fkey', 'reportbtkernelmodules', type_='foreignkey')
create_foreign_key('reportbtkernelmodules_backtrace_id_fkey', 'reportbtkernelmodules', 'reportbacktraces',
['backtrace_id'], ['id'])
drop_constraint('reportbacktraces_report_id_fkey', 'reportbacktraces', type_='foreignkey')
create_foreign_key('reportbacktraces_report_id_fkey', 'reportbacktraces', 'reports',
['report_id'], ['id'])
def downgrade():
op.drop_constraint(
"accounts_gpgkey_user_id_fkey", "accounts_gpgkey", type_="foreignkey"
)
op.create_foreign_key(
"accounts_gpgkey_user_id_fkey",
"accounts_gpgkey",
"accounts_user",
["user_id"],
["id"],
initially="DEFERRED",
deferrable=True,
)
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('Users', sa.Column('email', sa.String(length=50), nullable=False))
op.add_column('Users', sa.Column('first_name', sa.String(length=50), nullable=False))
op.add_column('Users', sa.Column('last_name', sa.String(length=50), nullable=False))
op.drop_constraint('Users_username_key', 'Users', type_='unique')
op.create_unique_constraint(None, 'Users', ['email'])
op.drop_column('Users', 'username')
# ### end Alembic commands ###
def downgrade():
context = op.get_context()
if context.bind.dialect.name == 'mssql':
op.drop_constraint('ck_ps_endpoints_dtls_fingerprint_sha_hash_values', 'ps_endpoints')
op.drop_column('ps_endpoints', 'dtls_fingerprint')
if context.bind.dialect.name == 'postgresql':
enum = ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME)
enum.drop(op.get_bind(), checkfirst=False)
"""
bind = op.get_bind()
session = Session(bind=bind)
# create table harbor_label
HarborLabel.__table__.create(bind)
# create table harbor_resource_label
HarborResourceLabel.__table__.create(bind)
# create user_group
UserGroup.__table__.create(bind)
# project member
op.drop_constraint('project_member_ibfk_1', 'project_member', type_='foreignkey')
op.drop_constraint('project_member_ibfk_2', 'project_member', type_='foreignkey')
op.drop_constraint('project_member_ibfk_3', 'project_member', type_='foreignkey')
op.drop_constraint('PRIMARY', 'project_member', type_='primary')
op.drop_index('user_id', 'project_member')
op.drop_index('role', 'project_member')
op.execute('ALTER TABLE project_member ADD id INT PRIMARY KEY AUTO_INCREMENT;')
op.alter_column('project_member', 'user_id', existing_type=sa.Integer, existing_nullable=False, new_column_name='entity_id')
op.alter_column('project_member', 'creation_time', existing_type=mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP"))
op.alter_column('project_member', 'update_time', existing_type=mysql.TIMESTAMP, server_default=sa.text("CURRENT_TIMESTAMP"), onupdate=sa.text("CURRENT_TIMESTAMP"))
op.add_column('project_member', sa.Column('entity_type', sa.String(1)))
session.query(ProjectMember).update({
ProjectMember.entity_type: 'u'
})
op.alter_column('project_member', 'entity_type', existing_type=sa.String(1), existing_nullable=True, nullable=False)
sa.Column('state', sa.Text(), nullable=False),
sa.Column('block_number', sa.Numeric(), nullable=False),
sa.Column('block_hash', sa.String(length=66), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('pk_block_task_meta'))
)
op.alter_column('logs', 'address',
existing_type=sa.VARCHAR(length=42),
nullable=False)
op.drop_constraint('fk_logs_transaction_hash_transactions', 'logs', type_='foreignkey')
op.drop_constraint('fk_logs_block_number_blocks', 'logs', type_='foreignkey')
op.create_foreign_key(op.f('fk_logs_transaction_hash_transactions'), 'logs', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
op.create_foreign_key(op.f('fk_logs_block_number_blocks'), 'logs', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
op.drop_constraint('fk_meta_info_last_pushed_block_blocks', 'meta_info', type_='foreignkey')
op.create_foreign_key(op.f('fk_meta_info_last_pushed_block_blocks'), 'meta_info', 'blocks', ['last_pushed_block'], ['block_number'], ondelete='CASCADE')
op.drop_constraint('fk_receipts_transaction_hash_transactions', 'receipts', type_='foreignkey')
op.drop_constraint('fk_receipts_block_number_blocks', 'receipts', type_='foreignkey')
op.create_foreign_key(op.f('fk_receipts_transaction_hash_transactions'), 'receipts', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
op.create_foreign_key(op.f('fk_receipts_block_number_blocks'), 'receipts', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
op.alter_column('state_diff', 'address',
existing_type=sa.VARCHAR(length=42),
nullable=False)
op.drop_constraint('fk_state_diff_block_number_blocks', 'state_diff', type_='foreignkey')
op.drop_constraint('fk_state_diff_transaction_hash_transactions', 'state_diff', type_='foreignkey')
op.create_foreign_key(op.f('fk_state_diff_block_number_blocks'), 'state_diff', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
op.create_foreign_key(op.f('fk_state_diff_transaction_hash_transactions'), 'state_diff', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
op.drop_constraint('fk_storage_address_state', 'storage', type_='foreignkey')
op.create_foreign_key(op.f('fk_storage_address_state'), 'storage', 'state', ['address'], ['address'], ondelete='CASCADE')
op.drop_constraint('fk_storage_diff_block_number_blocks', 'storage_diff', type_='foreignkey')
op.drop_constraint('fk_storage_diff_transaction_hash_transactions', 'storage_diff', type_='foreignkey')
op.drop_constraint('fk_storage_diff_state_diff_id_state_diff', 'storage_diff', type_='foreignkey')
op.create_foreign_key(op.f('fk_storage_diff_block_number_blocks'), 'storage_diff', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
op.create_foreign_key(op.f('fk_storage_diff_transaction_hash_transactions'), 'storage_diff', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column(u'users', 'is_group_owner')
op.drop_constraint(op.f('uq_locks_lock_id'), 'locks', type_='unique')
op.add_column(u'blueprints', sa.Column('plugin', sa.VARCHAR(length=32), autoincrement=False, nullable=True))
op.drop_constraint(op.f('fk_blueprints_group_id_groups'), 'blueprints', type_='foreignkey')
op.drop_constraint(op.f('fk_blueprints_template_id_blueprint_templates'), 'blueprints', type_='foreignkey')
op.create_foreign_key(u'fk_blueprints_plugin_plugins', 'blueprints', 'plugins', ['plugin'], ['id'])
op.drop_column(u'blueprints', 'template_id')
op.drop_column(u'blueprints', 'group_id')
op.drop_table('groups_users')
op.drop_table('groups_owners')
op.drop_table('groups_banned_users')
op.drop_table('blueprint_templates')
op.drop_table('groups')
### end Alembic commands ###