"""adding User model and tying relation to Qualifying_Answer

Revision ID: 686427549b61
Revises: 9f02092798e8
Create Date: 2019-03-17 14:10:00.525383

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '686427549b61'
down_revision = '9f02092798e8'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('qualifying__question',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('question', sa.Text(), nullable=True),
    sa.Column('help_text', sa.Text(), nullable=True),
    sa.Column('disqualifying_answer', sa.String(length=250), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=32), nullable=True),
    sa.Column('email', sa.String(length=120), nullable=True),
    sa.Column('pw_hash', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
    op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True)
    op.create_table('qualifying__answer',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_session', sa.String(length=250), nullable=True),
    sa.Column('question_id', sa.String(length=250), nullable=True),
    sa.Column('answer', sa.Text(), nullable=True),
    sa.Column('qualifying_answer', sa.String(length=250), nullable=True),
    sa.Column('question_version_number', sa.Float(asdecimal=True), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('answerer_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['answerer_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_qualifying__answer_timestamp'), 'qualifying__answer', ['timestamp'], unique=False)
    op.create_index(op.f('ix_qualifying__answer_user_session'), 'qualifying__answer', ['user_session'], unique=True)
    op.drop_table('qualifying__questions')
    op.drop_index('ix_qualifying__answers_timestamp', table_name='qualifying__answers')
    op.drop_index('ix_qualifying__answers_user_session', table_name='qualifying__answers')
    op.drop_table('qualifying__answers')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('qualifying__answers',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('user_session', sa.VARCHAR(length=250), nullable=True),
    sa.Column('question_id', sa.VARCHAR(length=250), nullable=True),
    sa.Column('answer', sa.TEXT(), nullable=True),
    sa.Column('qualifying_answer', sa.VARCHAR(length=250), nullable=True),
    sa.Column('question_version_number', sa.FLOAT(), nullable=True),
    sa.Column('timestamp', sa.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_qualifying__answers_user_session', 'qualifying__answers', ['user_session'], unique=1)
    op.create_index('ix_qualifying__answers_timestamp', 'qualifying__answers', ['timestamp'], unique=False)
    op.create_table('qualifying__questions',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('question', sa.TEXT(), nullable=True),
    sa.Column('help_text', sa.TEXT(), nullable=True),
    sa.Column('disqualifying_answer', sa.VARCHAR(length=250), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_index(op.f('ix_qualifying__answer_user_session'), table_name='qualifying__answer')
    op.drop_index(op.f('ix_qualifying__answer_timestamp'), table_name='qualifying__answer')
    op.drop_table('qualifying__answer')
    op.drop_index(op.f('ix_user_username'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('qualifying__question')
    # ### end Alembic commands ###
