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_app(app_id, system_app_type):
update = OAuthApplication.__table__.update()
if app_id.isdigit():
update = update.where(OAuthApplication.__table__.c.id == int(app_id))
else:
update = update.where(OAuthApplication.__table__.c.client_id == app_id)
op.execute(update.values(system_app_type=system_app_type, **system_app_type.enforced_data))
def upgrade(pyramid_env):
with context.begin_transaction():
op.add_column('idea', sa.Column(
'rdf_type', sa.String(60), nullable=False,
server_default='idea:GenericIdeaNode'))
op.add_column('idea', sa.Column(
'last_modified', sa.types.TIMESTAMP))
op.add_column('idea_idea_link', sa.Column(
'rdf_type', sa.String(60), nullable=False,
server_default='idea:InclusionRelation'))
op.drop_table("root_idea")
with context.begin_transaction():
op.execute('UPDATE idea SET "rdf_type" = "sqla_type"')
op.execute('UPDATE idea_idea_link SET "rdf_type" = "sqla_type"')
op.execute("UPDATE idea SET sqla_type = 'root_idea' WHERE sqla_type = 'assembl:RootIdea'")
op.execute("UPDATE idea SET sqla_type = 'idea' WHERE sqla_type <> 'root_idea'")
mark_changed()
with context.begin_transaction():
op.drop_column('idea_idea_link', 'sqla_type')
def upgrade():
context = op.get_context()
if context.bind.dialect.name == 'mysql':
for table in FW_TAB_NAME:
op.execute(SQL_STATEMENT_UPDATE_CMD % table)
def upgrade():
op.execute(CreateSchema('plugin_vc_vidyo'))
op.create_table('vidyo_extensions',
sa.Column('vc_room_id', sa.Integer(), nullable=False),
sa.Column('extension', sa.BigInteger(), nullable=True),
sa.Column('owned_by_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['vc_room_id'], ['events.vc_rooms.id'],
name='vidyo_extensions_vc_room_id_fkey'),
sa.PrimaryKeyConstraint('vc_room_id', name='vidyo_extensions_pkey'),
sa.Index('ix_plugin_vc_vidyo_vidyo_extensions_extension', 'extension'),
sa.Index('ix_plugin_vc_vidyo_vidyo_extensions_owned_by_id', 'owned_by_id'),
schema='plugin_vc_vidyo')
def upgrade():
op.execute("UPDATE journalcomment SET content = substring(content for 10000) WHERE length(content) > 10000")
op.execute("UPDATE searchtag SET title = substring(title for 162) WHERE length(title) > 162")
op.alter_column('ads', 'owner',
existing_type=sa.TEXT(),
type_=sa.String(length=254),
existing_nullable=False)
op.alter_column('character', 'content',
existing_type=sa.TEXT(),
type_=sa.String(length=100000),
existing_nullable=False,
existing_server_default=sa.text(u"''::text"))
op.alter_column('charcomment', 'content',
existing_type=sa.TEXT(),
type_=sa.String(length=10000),
existing_nullable=False)
op.alter_column('commishdesc', 'content',
#op.add_column('twitter_tweets', sa.Column('stored_at', sa.TIMESTAMP(), server_default=sa.text(u'CURRENT_TIMESTAMP'), nullable=True))
#op.create_index('stored_at_idx', 'twitter_tweets', ['stored_at'], unique=False)
### end Alembic commands ###
# NOTE: Since alembic presently doesn't support multiple
# alter_specifications per ALTER TABLE statement, it could take some hours
# to execute the following logic in individual ALTER TABLE statements on the
# 12+ million row tables. So, we construct SQL by hand to work around this.
# While adding the stored_at column, we wish it to have NULL in the
# pre-existing rows, since we really don't know when they were inserted. To
# accomplish this, we define the column with DEFAULT NULL in the first
# operation and then MODIFY it with DEFAULT CURRENT_TIMESTAMP in the second.
# Combining both those operations into one was resulted in "unknown column"
# error from MySQL.
op.execute(
"ALTER TABLE `twitter_tweet_samples` "
" ADD COLUMN `stored_at` TIMESTAMP NULL DEFAULT NULL"
)
op.execute(
"ALTER TABLE `twitter_tweet_samples` "
" MODIFY COLUMN `stored_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, "
" ADD INDEX `stored_at_idx` (`stored_at`)"
)
op.execute(
"ALTER TABLE `twitter_tweets` "
" ADD COLUMN `stored_at` TIMESTAMP NULL DEFAULT NULL"
)
)
op.create_foreign_key(
"user_fk", "reference", "user", ["user_id"], ["id"], ondelete="cascade"
)
op.execute(
"UPDATE reference SET type = 'inline' WHERE inline_message_id is not NULL"
)
op.execute(
"UPDATE reference \
SET type='admin', message_id=admin_message_id, user_id=admin_user_id \
WHERE admin_user_id is not NULL;"
)
op.execute(
"UPDATE reference \
SET type='private_vote', message_id=vote_message_id, user_id=vote_user_id \
WHERE vote_user_id is not NULL;"
)
op.drop_index("ix_reference_vote_user_id", table_name="reference")
op.drop_constraint("vote_user", "reference", type_="foreignkey")
op.drop_column("reference", "vote_user_id")
op.drop_column("reference", "vote_message_id")
op.drop_index("ix_reference_admin_user_id", table_name="reference")
op.drop_constraint("admin_user", "reference", type_="foreignkey")
op.drop_column("reference", "admin_user_id")
op.drop_column("reference", "admin_message_id")
op.alter_column(
def postgres_drop_views():
op.execute("DROP VIEW IF EXISTS data_samples_view;")
op.execute("DROP VIEW IF EXISTS syslog_view;")
op.execute("DROP VIEW IF EXISTS event_sensor_data_view;")
op.execute("DROP VIEW IF EXISTS data_sensors_view;")
op.execute("DROP VIEW IF EXISTS node_features_view;")
def upgrade():
bind = op.get_bind()
op.drop_constraint('watchlist_creator_id_fkey', 'watchlist')
op.drop_constraint('entity_watchlist_id_fkey', 'entity')
op.rename_table('watchlist', 'collection')
op.alter_column('entity', 'watchlist_id', new_column_name='collection_id')
tmp_type.create(bind, checkfirst=False)
op.execute('ALTER TABLE permission ALTER COLUMN resource_type TYPE perm_type_coll'
' USING resource_type::text::perm_type_coll;')
op.alter_column('permission', 'resource_type', type_=tmp_type,
existing_type=old_type)
meta = sa.MetaData()
meta.bind = bind
meta.reflect()
permission = meta.tables['permission']
q = sa.update(permission).where(permission.c.resource_type == 'watchlist')
q = q.values(resource_type='collection')
op.execute(q)
old_type.drop(bind, checkfirst=False)
new_type.create(bind, checkfirst=False)
op.execute('ALTER TABLE permission ALTER COLUMN resource_type TYPE permission_type'
' USING resource_type::text::permission_type;')
tmp_type.drop(bind, checkfirst=False)
)
op.execute("ALTER TABLE metrics_gender_cache DROP PRIMARY KEY")
op.execute(
"ALTER TABLE metrics_gender_cache ADD COLUMN participant_origin VARCHAR(50) DEFAULT '';"
)
op.execute(
"ALTER TABLE metrics_gender_cache ADD PRIMARY KEY (`date_inserted`, `type`, `enrollment_status`, `hpo_id`, "
"`hpo_name`,`date`, `gender_name`, `participant_origin`)"
)
op.execute("ALTER TABLE metrics_age_cache DROP PRIMARY KEY")
op.execute(
"ALTER TABLE metrics_age_cache ADD COLUMN participant_origin VARCHAR(50) DEFAULT '';"
)
op.execute(
"ALTER TABLE metrics_age_cache ADD PRIMARY KEY (`date_inserted`, `type`, `hpo_id`, `hpo_name`,`date`, "
"`age_range`, `enrollment_status`, `participant_origin`)"
)
op.execute("ALTER TABLE metrics_race_cache DROP PRIMARY KEY")
op.execute(
"ALTER TABLE metrics_race_cache ADD COLUMN participant_origin VARCHAR(50) DEFAULT '';"
)
op.execute(
"ALTER TABLE metrics_race_cache ADD PRIMARY KEY (`date_inserted`, `type`, `registered_flag`, "
"`participant_flag`, `consent_flag`, `core_flag`, `hpo_id`, `hpo_name`,`date`, `participant_origin`)"
)
op.execute("ALTER TABLE metrics_region_cache DROP PRIMARY KEY")
op.execute(
"ALTER TABLE metrics_region_cache ADD COLUMN participant_origin VARCHAR(50) DEFAULT '';"