How to use the alembic.op.execute function in alembic

To help you get started, we’ve selected a few alembic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github indico / indico / indico / migrations / versions / 201708301158_09fd62e56097_add_oauth_system_app_type.py View on Github external
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))
github assembl / assembl / assembl / alembic / versions / 43863df11763_isolate_idea_rdf_type.py View on Github external
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')
github openstack / neutron-fwaas / neutron_fwaas / db / migration / alembic_migrations / versions / mitaka / contract / 458aa42b14b_fw_table_alter.py View on Github external
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)
github indico / indico-plugins / vc_vidyo / indico_vc_vidyo / migrations / 201502191158_a702ad0bcea_create_extensions_table.py View on Github external
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')
github Weasyl / weasyl / libweasyl / libweasyl / alembic / versions / dddf9a5cdd08_add_initial_length_limits.py View on Github external
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',
github numenta / numenta-apps / taurus_metric_collectors / taurus_metric_collectors / collectorsdb / migrations / versions / 014_12c41f6f39a_adds_stored_at_column_in_.py View on Github external
#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"
    )
github Nukesor / ultimate-poll-bot / migrations / versions / 2020_04_10_5a8b94fb9dd9_refactor_reference.py View on Github external
)
    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(
github intel-ctrlsys / sensys / contrib / database / schema_migration / versions / d79399c4d070_updating_all_value_str_to_text_from_.py View on Github external
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;")
github alephdata / aleph / aleph / migrate / versions / afd5bb9f5004_rename_watchlists.py View on Github external
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)
github all-of-us / raw-data-repository / rdr_service / alembic / versions / 407b2b8a20d8_add_participant_origin_column_to_.py View on Github external
)

    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 '';"