"""refactor instances

Revision ID: 97e1b61fb3bd
Revises: 948d85570ae5
Create Date: 2020-12-04 18:42:47.567115

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '97e1b61fb3bd'
down_revision = '948d85570ae5'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('instances',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.Text(), nullable=True),
    sa.Column('workshop_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['workshop_id'], ['workshops.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_instances_email'), 'instances', ['email'], unique=False)
    op.create_index(op.f('ix_instances_workshop_id'), 'instances', ['workshop_id'], unique=False)
    op.add_column('instance_events', sa.Column('instance_id', sa.Integer(), nullable=True))
    op.create_index(op.f('ix_instance_events_instance_id'), 'instance_events', ['instance_id'], unique=False)
    op.drop_index('ix_instance_events_email', table_name='instance_events')
    op.drop_index('ix_instance_events_name', table_name='instance_events')
    op.drop_index('ix_instance_events_workshop_id', table_name='instance_events')
    op.drop_constraint('instance_events_workshop_id_fkey', 'instance_events', type_='foreignkey')
    op.create_foreign_key(None, 'instance_events', 'instances', ['instance_id'], ['id'])
    op.drop_column('instance_events', 'email')
    op.drop_column('instance_events', 'name')
    op.drop_column('instance_events', 'workshop_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('instance_events', sa.Column('workshop_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('instance_events', sa.Column('name', sa.TEXT(), autoincrement=False, nullable=True))
    op.add_column('instance_events', sa.Column('email', sa.TEXT(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'instance_events', type_='foreignkey')
    op.create_foreign_key('instance_events_workshop_id_fkey', 'instance_events', 'workshops', ['workshop_id'], ['id'])
    op.create_index('ix_instance_events_workshop_id', 'instance_events', ['workshop_id'], unique=False)
    op.create_index('ix_instance_events_name', 'instance_events', ['name'], unique=False)
    op.create_index('ix_instance_events_email', 'instance_events', ['email'], unique=False)
    op.drop_index(op.f('ix_instance_events_instance_id'), table_name='instance_events')
    op.drop_column('instance_events', 'instance_id')
    op.drop_index(op.f('ix_instances_workshop_id'), table_name='instances')
    op.drop_index(op.f('ix_instances_email'), table_name='instances')
    op.drop_table('instances')
    # ### end Alembic commands ###
