"""empty message

Revision ID: 582315d9543d
Revises: 
Create Date: 2018-11-13 21:32:26.287985

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '582315d9543d'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    subjects = op.create_table('subjects',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('date_modified', sa.DateTime(), nullable=True),
        sa.Column('name', sa.String(length=120), nullable=False),
        sa.Column('prerequisite', sa.Integer(), nullable=False),
        sa.Column('minimum_approved', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    types = op.create_table('types',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('date_modified', sa.DateTime(), nullable=True),
        sa.Column('name', sa.String(length=100), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    users = op.create_table('users',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('date_modified', sa.DateTime(), nullable=True),
        sa.Column('name', sa.String(length=150), nullable=False),
        sa.Column('email', sa.String(length=250), nullable=False),
        sa.Column('password', sa.String(length=250), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('email')
    )
    nodes = op.create_table('nodes',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('date_modified', sa.DateTime(), nullable=True),
        sa.Column('answer_parent', sa.String(length=250), nullable=False),
        sa.Column('parent_node', sa.Integer(), nullable=False),
        sa.Column('score', sa.Integer(), nullable=False),
        sa.Column('type_id', sa.Integer(), nullable=False),
        sa.Column('subject_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['subject_id'], ['subjects.id'], ),
        sa.ForeignKeyConstraint(['type_id'], ['types.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    user_subjects_rel = op.create_table('user_subjects_approved',
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('subject_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['subject_id'], ['subjects.id'], ),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
        sa.PrimaryKeyConstraint('user_id', 'subject_id')
    )

    # Seeding database
    op.bulk_insert(subjects, [
        {'name': 'Variables', 'minimum_approved': 10, 'prerequisite': 0},
        {'name': 'Estructuras de Control', 'minimum_approved': 15, 'prerequisite': 1}
    ])

    op.bulk_insert(types, [
        {'name': 'Correcta'},
        {'name': 'Incorrecta'},
    ])

    op.bulk_insert(nodes, [
        {'subject_id': 1, 'type_id': 1, 'score': 10, 'answer_parent': 'None', 'parent_node': 0},
        {'subject_id': 1, 'type_id': 1, 'score': -5, 'answer_parent': 'c = 15', 'parent_node': 1},
        {'subject_id': 1, 'type_id': 2, 'score': 10, 'answer_parent': 'c = \'15\'', 'parent_node': 1},
        {'subject_id': 1, 'type_id': 2, 'score': -5, 'answer_parent': 'Error', 'parent_node': 1},
    ])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_subjects_approved')
    op.drop_table('nodes')
    op.drop_table('users')
    op.drop_table('types')
    op.drop_table('subjects')
    # ### end Alembic commands ###
