Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_existing_records():
session = sa.orm.Session(bind=op.get_bind())
values = []
with session.begin(subtransactions=True):
for row in session.query(TBL_MODEL):
# NOTE from kevinbenton: without this disabled, pylint complains
# about a missing 'dml' argument.
#pylint: disable=no-value-for-parameter
res = session.execute(
standardattrs.insert().values(resource_type=TBL)
)
session.execute(
TBL_MODEL.update().values(
standard_attr_id=res.inserted_primary_key[0]).where(
TBL_MODEL.c.id == row[0])
)
# this commit is necessary to allow further operations
session.commit()
def upgrade():
op.drop_column('messages', 'company_name')
db_manager.Session.remove()
db_manager.Session.configure(bind=op.get_bind())
session = db_manager.Session()
db_manager.set_meta_data('schema_version', 5, session=session)
session.commit()
def upgrade():
"""Transform individual access rules states to 'access_rules_status'.
WARNING: This method performs lossy converting of existing data in DB.
"""
op.add_column(
'share_instances',
Column('access_rules_status', String(length=255))
)
connection = op.get_bind()
share_instances_table = utils.load_table('share_instances', connection)
instance_access_table = utils.load_table('share_instance_access_map',
connection)
# NOTE(u_glide): Data migrations shouldn't be performed on live clouds
# because it will lead to unpredictable behaviour of running operations
# like migration.
instances_query = (
share_instances_table.select()
.where(share_instances_table.c.status == constants.STATUS_AVAILABLE)
.where(share_instances_table.c.deleted == 'False')
)
for instance in connection.execute(instances_query):
access_mappings_query = instance_access_table.select().where(
def upgrade():
conn = op.get_bind()
isolated = [sa.text('SELECT NOT EXISTS (SELECT 1 FROM %s WHERE EXISTS '
'(SELECT 1 FROM source WHERE pk = %s.source_pk AND id = :id))' % (tab, tab), conn)
for tab in ('languagesource', 'valuesetreference')]
isolated.append(sa.text('SELECT NOT EXISTS (SELECT 1 FROM '
"(SELECT pk, unnest(regexp_matches(description, '\*\*(\d+)\*\*', 'g')) AS ref_id "
"FROM valueset WHERE description != '') AS m "
'WHERE ref_id = :id)', conn))
unlink = [sa.text('DELETE FROM %s WHERE EXISTS '
'(SELECT 1 FROM source WHERE pk = %s.ref_pk AND id = :id)' % (tab, tab), conn)
for tab in ('refcountry', 'refdoctype', 'refmacroarea', 'refprovider')]
del_ref = sa.text('DELETE FROM ref WHERE EXISTS '
'(SELECT 1 FROM source WHERE PK = ref.pk AND id = :id)', conn)
del_source = sa.text('DELETE FROM source WHERE id = :id', conn)
insert_repl = sa.text('INSERT INTO config (created, updated, active, key, value) '
'SELECT now(), now(), TRUE, :key, :value '
'WHERE NOT EXISTS (SELECT 1 FROM config WHERE key = :key)', conn)
def upgrade():
"""Migrations for the upgrade."""
conn = op.get_bind()
statement = text(
"""
UPDATE db_dbnode
SET attributes = jsonb_set(attributes, '{"sealed"}', attributes->'_sealed')
WHERE attributes ? '_sealed' AND node_type LIKE 'process.%';
-- Copy `_sealed` -> `sealed`
UPDATE db_dbnode SET attributes = attributes - '_sealed'
WHERE attributes ? '_sealed' AND node_type LIKE 'process.%';
-- Delete `_sealed`
UPDATE db_dbnode SET attributes = attributes - '_finished'
WHERE attributes ? '_finished' AND node_type LIKE 'process.%';
-- Delete `_finished`
Column('updated_at', DateTime),
Column('deleted_at', DateTime),
Column('deleted', String(length=36), default='False'),
Column('id', String(length=36), primary_key=True, nullable=False),
Column('share_instance_id', String(length=36),
ForeignKey('share_instances.id', name="siam_instance_fk")),
Column('access_id', String(length=36),
ForeignKey('share_access_map.id', name="siam_access_fk")),
Column('state', String(length=255)),
mysql_engine='InnoDB',
mysql_charset='utf8')
# NOTE(u_glide): Move all states from 'share_access_map'
# to 'share_instance_access_map'
instance_access_mappings = []
connection = op.get_bind()
access_table = utils.load_table('share_access_map', connection)
instances_table = utils.load_table('share_instances', connection)
for access_rule in connection.execute(access_table.select()):
# pylint: disable=assignment-from-no-return
instances_query = instances_table.select().where(
instances_table.c.share_id == access_rule.share_id
)
for instance in connection.execute(instances_query):
instance_access_mappings.append({
'created_at': access_rule.created_at,
'updated_at': access_rule.updated_at,
'deleted_at': access_rule.deleted_at,
'deleted': access_rule.deleted,
'id': uuidutils.generate_uuid(),
# " WHERE uc.course_role IN ('Instructor', 'Teaching Assistant'))"
# )
# ... use a potentially slower query
update = text(
"UPDATE answer SET comparable = 0 "
"WHERE EXISTS ( "
" SELECT 1 "
" FROM user_course "
" JOIN assignment "
" ON assignment.course_id = user_course.course_id "
" WHERE "
" assignment.id = answer.assignment_id "
" AND user_course.user_id = answer.user_id "
" AND user_course.course_role IN ('Instructor', 'Teaching Assistant'))"
)
op.get_bind().execute(update)
def upgrade():
# Create a tempoary "_type" type, convert and drop the "old" type
tmp_type.create(op.get_bind(), checkfirst=False)
op.execute(
"ALTER TABLE responses ALTER COLUMN type TYPE _type" " USING type::TEXT::_type"
)
old_type.drop(op.get_bind(), checkfirst=False)
# Create and convert to the "new" type type
new_type.create(op.get_bind(), checkfirst=False)
op.execute(
"ALTER TABLE responses ALTER COLUMN type TYPE type" " USING type::TEXT::type"
)
tmp_type.drop(op.get_bind(), checkfirst=False)
def upgrade():
engine = op.get_bind()
if engine.dialect.dialect_description.startswith('mysql'):
engine.execute('SET FOREIGN_KEY_CHECKS=0')
if engine.dialect.dialect_description == 'postgresql+psycopg2':
op.drop_constraint('package_to_tag_package_id_fkey',
'package_to_tag', 'foreignkey')
op.drop_constraint('package_to_tag_tag_id_fkey',
'package_to_tag', 'foreignkey')
op.drop_constraint('package_to_category_package_id_fkey',
'package_to_category', 'foreignkey')
op.drop_constraint('class_definition_package_id_fkey',
'class_definition', 'foreignkey')
helpers.transform_table(
'package', {}, {},
sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('updated', sa.DateTime(), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
def upgrade():
connection = op.get_bind()
nodes = table('nodes',
column('path', sa.String(2048)),
column('node', sa.Integer),
column('parent', sa.Integer))
n1 = nodes.alias('n1')
n2 = nodes.alias('n2')
policy = table('policy',
column('node', sa.Integer),
column('key', sa.String(128)),
column('value', sa.String(256)))
s = select([n2.c.node, n1.c.path])
s = s.where(n2.c.parent == n1.c.node)
s = s.where(n1.c.parent == ROOTNODE)
s = s.where(n1.c.node != ROOTNODE)