"""empty message

Revision ID: b7b64433b134
Revises: 2d2e6562586a
Create Date: 2021-03-29 23:08:30.541279

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

# revision identifiers, used by Alembic.
revision = 'b7b64433b134'
down_revision = '2d2e6562586a'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('medical_records',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('date_of_admission', sa.DateTime(), nullable=False),
    sa.Column('first_diagnosis', sa.Text(), nullable=False),
    sa.Column('last_diagnosis', sa.Text(), nullable=False),
    sa.Column('date_of_discharge', sa.DateTime(), nullable=False),
    sa.Column('patient_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['patient_id'], ['patients.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_index('code', table_name='drugs')
    op.drop_table('drugs')
    op.drop_table('chemists')
    op.add_column('patients', sa.Column('birth_place', sa.String(length=255), nullable=False))
    op.add_column('patients', sa.Column('is_hospitalized', sa.Boolean(), nullable=True))
    op.add_column('patients', sa.Column('tax_code', sa.String(length=20), nullable=False))
    op.create_unique_constraint(None, 'patients', ['tax_code'])
    op.drop_constraint('patients_ibfk_1', 'patients', type_='foreignkey')
    op.drop_column('patients', 'department_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('patients', sa.Column('department_id', mysql.INTEGER(), autoincrement=False, nullable=False))
    op.create_foreign_key('patients_ibfk_1', 'patients', 'departments', ['department_id'], ['id'])
    op.drop_constraint(None, 'patients', type_='unique')
    op.drop_column('patients', 'tax_code')
    op.drop_column('patients', 'is_hospitalized')
    op.drop_column('patients', 'birth_place')
    op.create_table('chemists',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_table('drugs',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('code', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('name', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('quantity', mysql.FLOAT(), nullable=True),
    sa.Column('chemist_id', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['chemist_id'], ['chemists.id'], name='drugs_ibfk_1'),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.create_index('code', 'drugs', ['code'], unique=True)
    op.drop_table('medical_records')
    # ### end Alembic commands ###
