How to use the alembic.op.create_unique_constraint 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 alephdata / aleph / aleph / migrate / versions / 850a674e3ccf_drop_unique_on_cache.py View on Github external
def downgrade():
    op.drop_index(op.f('ix_cache_key'), table_name='cache')
    op.create_unique_constraint('cache_key_key', 'cache', ['key'])
github aiidateam / aiida-core / aiida / backends / sqlalchemy / migrations / versions / b8b23ddefad4_dbgroup_name_to_label_type_to_type_string.py View on Github external
def downgrade():
    """The downgrade migration actions."""
    # dropping
    op.drop_constraint('db_dbgroup_label_type_string_key', 'db_dbgroup')
    op.drop_index('ix_db_dbgroup_label', 'db_dbgroup')
    op.drop_index('ix_db_dbgroup_type_string', 'db_dbgroup')

    # renaming
    op.alter_column('db_dbgroup', 'label', new_column_name='name')
    op.alter_column('db_dbgroup', 'type_string', new_column_name='type')

    # creating
    op.create_unique_constraint('db_dbgroup_name_type_key', 'db_dbgroup', ['name', 'type'])
    op.create_index('ix_db_dbgroup_name', 'db_dbgroup', ['name'])
    op.create_index('ix_db_dbgroup_type', 'db_dbgroup', ['type'])
github projectweekend / Flask-PostgreSQL-API-Seed / migrations / versions / 277d8c8ed827_.py View on Github external
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint('uni_user_code', 'password_reset', ['user', 'code'])
    ### end Alembic commands ###
github cloudify-cosmo / cloudify-manager / resources / rest-service / cloudify / migrations / versions / 62a8d746d13b_5_0_to_5_0_5.py View on Github external
def _update_managers_table():
    op.add_column('managers', sa.Column('node_id', sa.Text(), nullable=True))
    op.add_column('managers',
                  sa.Column('last_seen', UTCDateTime(), nullable=False,
                            server_default=sa.func.current_timestamp()))
    op.add_column('managers',
                  sa.Column('status_report_frequency', sa.Integer(),
                            nullable=True))
    op.execute("""
      UPDATE managers
      SET node_id = hostname;
    """)
    op.alter_column('managers', 'node_id', nullable=False)
    op.create_unique_constraint(op.f('managers_node_id_key'), 'managers',
                                ['node_id'])
    op.create_index(op.f('managers_last_seen_idx'), 'managers', ['last_seen'],
                    unique=False)
github asterisk / asterisk / contrib / ast-db-manage / config / versions / 81b01a191a46_pjsip_add_contact_reg_server.py View on Github external
def downgrade():
    op.drop_constraint('ps_contacts_uq', 'ps_contacts', type_='unique')
    op.drop_column('ps_contacts', 'reg_server')
    op.create_unique_constraint(None, 'ps_contacts', 'id')
github aiidateam / aiida-core / aiida / backends / sqlalchemy / migrations / versions / 375c2db70663_dblog_uuid_uniqueness_constraint.py View on Github external
def upgrade():
    """Add unique key constraint to the UUID column."""
    op.create_unique_constraint('db_dblog_uuid_key', 'db_dblog', ['uuid'])
github openstack / manila / manila / db / migrations / alembic / versions / 38e632621e5a_change_volume_type_to_share_type.py View on Github external
sa.Column('volume_type_id', sa.String(length=36),
                  sa.ForeignKey('share_types.id'), nullable=False),
        sa.Column('key', sa.String(length=255)),
        sa.Column('value', sa.String(length=255)),
        mysql_engine='InnoDB')

    LOG.info(_LI("Migrating share_type_extra_specs to "
             "volume_type_extra_specs"))
    _copy_records(destination_table=vt_es, up_migration=False)

    LOG.info(_LI("Dropping share_type_extra_specs table"))
    op.drop_table("share_type_extra_specs")

    LOG.info(_LI("Renaming share_types table to volume_types"))
    op.drop_constraint('st_name_uc', 'share_types', type_='unique')
    op.create_unique_constraint('vt_name_uc', 'share_types',
                                ['name', 'deleted'])
    op.rename_table("share_types", "volume_types")

    LOG.info(_LI("Renaming column name shares.share_type_id to "
             "shares.volume_type.id"))
    op.alter_column("shares", "share_type_id",
                    new_column_name="volume_type_id",
                    type_=sa.String(length=36))
github Nukesor / ultimate-poll-bot / migrations / versions / 2019_06_06_5b172edeaf8d_show_percentage_option.py View on Github external
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint(
        "vote_user_id_poll_id_poll_option_id_key",
        "vote",
        ["user_id", "poll_id", "poll_option_id"],
    )
    op.drop_constraint("one_vote_per_option_and_user", "vote", type_="unique")
    op.alter_column(
        "poll",
        "results_visible",
        existing_type=sa.BOOLEAN(),
        server_default=sa.text("true"),
        existing_nullable=False,
    )
    op.drop_column("poll", "show_percentage")
    # ### end Alembic commands ###
github fedora-infra / bodhi / bodhi / server / migrations / versions / 95ce24bed77a_remove_the_ci_status_feature.py View on Github external
def downgrade():
    """Restore the fields, enums, and constraints removed in the upgrade() function."""
    op.add_column('builds', sa.Column('scm_url', sa.Unicode(length=256), nullable=True))
    op.create_unique_constraint('uq_scm_url', 'builds', ['scm_url'])
    op.execute(
        "CREATE TYPE ck_ci_status AS ENUM "
        "('ignored', 'queued', 'running', 'passed', 'failed', 'waiting')")
    op.add_column(
        'builds',
        sa.Column(
            'ci_status',
            sa.Enum(
                'ignored', 'queued', 'running', 'passed', 'failed', 'waiting',
                name='ck_ci_status'),
            nullable=True
        )
github CityOfNewYork / NYCOpenRecords / migrations / versions / 89d3f2e347f1_use_nyc_id_v2_0.py View on Github external
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint(None, "users", ["guid"])
    # op.drop_constraint('agency_users_user_guid_fkey', 'agency_users', type_='foreignkey')
    # op.create_foreign_key(None, 'agency_users', 'users', ['user_guid'], ['guid'])
    op.drop_column("agency_users", "auth_user_type")
    op.create_foreign_key(
        None, "agency_users", "users", ["user_guid"], ["guid"], onupdate="CASCADE"
    )
    # op.drop_constraint('events_user_guid_fkey', 'events', type_='foreignkey')
    op.drop_column("events", "auth_user_type")
    op.create_foreign_key(
        None, "events", "users", ["user_guid"], ["guid"], onupdate="CASCADE"
    )
    # op.drop_constraint('user_requests_user_guid_fkey', 'user_requests', type_='foreignkey')
    op.drop_column("user_requests", "auth_user_type")
    op.create_foreign_key(
        None, "user_requests", "users", ["user_guid"], ["guid"], onupdate="CASCADE"
    )