"""Add user_role table and fk user_account

Revision ID: 48f175eabbe4
Revises: 39a9fea061b9
Create Date: 2020-03-15 20:44:24.056534

"""
import salsa
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '48f175eabbe4'
down_revision = '39a9fea061b9'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_role',
    sa.Column('id', salsa.db.types.GUID(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('description', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_user_role')),
    sa.UniqueConstraint('description', name=op.f('uq_user_role_description')),
    sa.UniqueConstraint('title', name=op.f('uq_user_role_title'))
    )
    op.add_column('user_account', sa.Column('user_name', sa.String(length=255), nullable=False))
    op.add_column('user_account', sa.Column('user_role_id', salsa.db.types.GUID(), nullable=False))
    op.create_unique_constraint(op.f('uq_user_account_user_name'), 'user_account', ['user_name'])
    op.create_foreign_key(op.f('fk_user_account_user_role_id_user_role'), 'user_account', 'user_role', ['user_role_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f('fk_user_account_user_role_id_user_role'), 'user_account', type_='foreignkey')
    op.drop_constraint(op.f('uq_user_account_user_name'), 'user_account', type_='unique')
    op.drop_column('user_account', 'user_role_id')
    op.drop_column('user_account', 'user_name')
    op.drop_table('user_role')
    # ### end Alembic commands ###
