"""empty message

Revision ID: ccc32cd9b882
Revises: 450fb000651f
Create Date: 2019-01-23 18:50:53.884980

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'ccc32cd9b882'
down_revision = '450fb000651f'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('payments',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('teacher_id', sa.Integer(), nullable=False),
                    sa.Column('student_id', sa.Integer(), nullable=True),
                    sa.Column('amount', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.ForeignKeyConstraint(['student_id'], ['students.id'], ),
                    sa.ForeignKeyConstraint(['teacher_id'], ['teachers.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('lesson_topics',
                    sa.Column('topic_id', sa.Integer(), nullable=False),
                    sa.Column('lesson_id', sa.Integer(), nullable=False),
                    sa.Column('is_finished', sa.Boolean(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.ForeignKeyConstraint(['lesson_id'], ['lessons.id'], ),
                    sa.ForeignKeyConstraint(['topic_id'], ['topics.id'], ),
                    sa.PrimaryKeyConstraint('topic_id', 'lesson_id')
                    )
    op.drop_constraint('topics_stage_id_fkey', 'topics', type_='foreignkey')
    op.drop_column('topics', 'stage_id')
    op.drop_table('stages')
    op.add_column('lessons', sa.Column(
        'lesson_number', sa.Integer(), nullable=True))
    op.drop_constraint('lessons_topic_id_fkey', 'lessons', type_='foreignkey')
    op.drop_column('lessons', 'mark_topic')
    op.drop_column('lessons', 'topic_id')
    op.add_column('topics', sa.Column(
        'max_lesson_number', sa.Integer(), nullable=False))
    op.add_column('topics', sa.Column(
        'min_lesson_number', sa.Integer(), nullable=False))

    op.drop_column('topics', 'order')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('topics', sa.Column('order', sa.INTEGER(),
                                      autoincrement=False, nullable=True))
    op.add_column('topics', sa.Column('stage_id', sa.INTEGER(),
                                      autoincrement=False, nullable=False))
    op.create_foreign_key('topics_stage_id_fkey', 'topics',
                          'stages', ['stage_id'], ['id'])
    op.drop_column('topics', 'min_lesson_number')
    op.drop_column('topics', 'max_lesson_number')
    op.add_column('lessons', sa.Column('topic_id', sa.INTEGER(),
                                       autoincrement=False, nullable=True))
    op.add_column('lessons', sa.Column(
        'mark_topic', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.create_foreign_key('lessons_topic_id_fkey',
                          'lessons', 'topics', ['topic_id'], ['id'])
    op.drop_column('lessons', 'lesson_number')
    op.create_table('stages',
                    sa.Column('id', sa.INTEGER(),
                              autoincrement=True, nullable=False),
                    sa.Column('title', sa.VARCHAR(),
                              autoincrement=False, nullable=False),
                    sa.Column('order', sa.INTEGER(),
                              autoincrement=False, nullable=False),
                    sa.Column('created_at', postgresql.TIMESTAMP(),
                              autoincrement=False, nullable=False),
                    sa.PrimaryKeyConstraint('id', name='stages_pkey')
                    )
    op.drop_table('lesson_topics')
    op.drop_table('payments')
    # ### end Alembic commands ###
