"""Add QB Time Line Table

Revision ID: 9026af5fe040
Revises: 883fd1095361
Create Date: 2018-11-28 06:39:34.215999

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '9026af5fe040'
down_revision = 'e5aec2aebe7e'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'qb_timeline',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('at', sa.DateTime(), nullable=False),
        sa.Column('qb_id', sa.Integer(), nullable=True),
        sa.Column('qb_recur_id', sa.Integer(), nullable=True),
        sa.Column('qb_iteration', sa.Integer(), nullable=True),
        sa.Column('status', sa.Enum(
            'completed', 'due', 'expired', 'overdue',
            'partially_completed', 'in_progress', 'withdrawn',
            name='overallstatus'), nullable=False),
        sa.ForeignKeyConstraint(
            ['qb_id'], ['questionnaire_banks.id'], ondelete='cascade'),
        sa.ForeignKeyConstraint(
            ['qb_recur_id'], ['recurs.id'], ondelete='cascade'),
        sa.ForeignKeyConstraint(
            ['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'))
    op.create_index(
        op.f('ix_qb_timeline_at'), 'qb_timeline', ['at'], unique=False)
    op.create_index(
        op.f('ix_qb_timeline_status'), 'qb_timeline', ['status'],
        unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_qb_timeline_status'), table_name='qb_timeline')
    op.drop_index(op.f('ix_qb_timeline_at'), table_name='qb_timeline')
    op.drop_table('qb_timeline')
    op.execute("DROP TYPE overallstatus")
    # ### end Alembic commands ###
