"""Update db schema

Revision ID: b37b2a250b6a
Revises: 69a3090767a7
Create Date: 2020-12-06 15:32:45.936044

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

# revision identifiers, used by Alembic.
revision = 'b37b2a250b6a'
down_revision = '69a3090767a7'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('halls',
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('occupancy_of_hall', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('film_occupations_times',
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('film_id', sa.String(length=36), nullable=False),
    sa.Column('schedule_id', sa.String(length=36), nullable=False),
    sa.Column('start_time', sa.Time(), nullable=False),
    sa.Column('end_time', sa.Time(), nullable=False),
    sa.ForeignKeyConstraint(['film_id'], ['films.id'], ),
    sa.ForeignKeyConstraint(['schedule_id'], ['schedules.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('occupied_seats',
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('user_id', sa.String(length=36), nullable=False),
    sa.Column('film_ocupation_time_id', sa.String(length=36), nullable=False),
    sa.ForeignKeyConstraint(['film_ocupation_time_id'], ['film_occupations_times.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_table('filmsschedules')
    op.drop_table('busy_times')
    op.add_column('schedules', sa.Column('hall_id', sa.String(length=36), nullable=False))
    op.add_column('schedules', sa.Column('user_creator_id', sa.String(length=36), nullable=False))
    op.create_foreign_key(None, 'schedules', 'halls', ['hall_id'], ['id'])
    op.create_foreign_key(None, 'schedules', 'users', ['user_creator_id'], ['id'])
    op.drop_column('schedules', 'occupancy_of_hall')
    op.add_column('users', sa.Column('role', sa.String(length=25), nullable=False))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'role')
    op.add_column('schedules', sa.Column('occupancy_of_hall', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'schedules', type_='foreignkey')
    op.drop_constraint(None, 'schedules', type_='foreignkey')
    op.drop_column('schedules', 'user_creator_id')
    op.drop_column('schedules', 'hall_id')
    op.create_table('busy_times',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('film_id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('schedule_id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('start_time', mysql.TIME(), nullable=False),
    sa.Column('end_time', mysql.TIME(), nullable=False),
    sa.ForeignKeyConstraint(['film_id'], ['films.id'], name='busy_times_ibfk_1'),
    sa.ForeignKeyConstraint(['schedule_id'], ['schedules.id'], name='busy_times_ibfk_2'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8',
    mysql_engine='InnoDB'
    )
    op.create_table('filmsschedules',
    sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('film_id', mysql.VARCHAR(length=36), nullable=False),
    sa.Column('schedule_id', mysql.VARCHAR(length=36), nullable=False),
    sa.ForeignKeyConstraint(['film_id'], ['films.id'], name='filmsschedules_ibfk_1'),
    sa.ForeignKeyConstraint(['schedule_id'], ['schedules.id'], name='filmsschedules_ibfk_2'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8',
    mysql_engine='InnoDB'
    )
    op.drop_table('occupied_seats')
    op.drop_table('film_occupations_times')
    op.drop_table('halls')
    # ### end Alembic commands ###
