<commit_before>"""Add role column to users_tenants table
Revision ID: 406821843b55
Revises: <PASSWORD>
Create Date: 2017-10-01 19:37:31.484983
"""
from alembic import op
import sqlalchemy as sa
import manager_rest     # Adding this manually


# revision identifiers, used by Alembic.
revision = '406821843b55'
down_revision = '4dfd8797<PASSWORD>a'
branch_labels = None
depends_on = None


def upgrade():
    op.add_column(
        'users_tenants',
        sa.Column('role_id', sa.Integer()),
    )
    op.create_foreign_key(
        'users_tenants_role_id_fkey',
        'users_tenants',
        'roles',
        ['role_id'],
        ['id'],
    )
    op.create_primary_key(
        'users_tenants_pkey',
        'users_tenants',
        ['user_id', 'tenant_id'],
    )

    # Define with just the columns needed
    # to generate the UPDATE sql expression below
    users_tenants = sa.table(
        'users_tenants',
        sa.column('user_id', sa.Integer),
        sa.column('role_id', sa.Integer),
    )
    users_roles = sa.table(
        'users_roles',
        sa.column('user_id', sa.Integer),
        sa.column('role_id', sa.Integer),
    )
    op.execute(
        users_tenants.update()
        .values(role_id=(
            sa.select([users_roles.c.role_id])
            .where(users_tenants.c.user_id == users_roles.c.user_id)
        ))
    )


def downgrade():
    op.drop_constraint(
        'users_tenants_pkey',
        'users_tenants',
    )
    op.drop_constraint(
        'users_tenants_role_id_fkey',
        'users_tenants',
    )
    op.drop_column('users_tenants', 'role_id')
<commit_msg>CFY-7257 Set not null constraint to `users_tenants.role_id` column<commit_after>"""Add role column to users_tenants table
Revision ID: 406821843b55
Revises: 3496c876cd1a
Create Date: 2017-10-01 19:37:31.484983
"""
from alembic import op
import sqlalchemy as sa
import manager_rest     # Adding this manually


# revision identifiers, used by Alembic.
revision = '406821843b55'
down_revision = '4dfd8797<PASSWORD>a'
branch_labels = None
depends_on = None


def upgrade():
    op.add_column(
        'users_tenants',
        sa.Column('role_id', sa.Integer()),
    )
    op.create_foreign_key(
        'users_tenants_role_id_fkey',
        'users_tenants',
        'roles',
        ['role_id'],
        ['id'],
    )
    op.create_primary_key(
        'users_tenants_pkey',
        'users_tenants',
        ['user_id', 'tenant_id'],
    )

    # Define with just the columns needed
    # to generate the UPDATE sql expression below
    users_tenants = sa.table(
        'users_tenants',
        sa.column('user_id', sa.Integer),
        sa.column('role_id', sa.Integer),
    )
    users_roles = sa.table(
        'users_roles',
        sa.column('user_id', sa.Integer),
        sa.column('role_id', sa.Integer),
    )
    op.execute(
        users_tenants.update()
        .values(role_id=(
            sa.select([users_roles.c.role_id])
            .where(users_tenants.c.user_id == users_roles.c.user_id)
        ))
    )
    op.alter_column('users_tenants', 'role_id', nullable=False)


def downgrade():
    op.drop_constraint(
        'users_tenants_pkey',
        'users_tenants',
    )
    op.drop_constraint(
        'users_tenants_role_id_fkey',
        'users_tenants',
    )
    op.drop_column('users_tenants', 'role_id')

{'fraction_non_alphanumeric': 0.12092187967674349, 'fraction_numerical': 0.03172702783597725, 'mean_word_length': 2.6405228758169934, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5331174', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1154, 'n_words': 212}