"""empty message

Revision ID: edc2261bfd64
Revises: 802c20ccb94d
Create Date: 2021-06-29 20:29:52.072410

"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils

# revision identifiers, used by Alembic.
revision = 'edc2261bfd64'
down_revision = '802c20ccb94d'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('sessions',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('session_id', sa.VARCHAR(length=255), nullable=True),
    sa.Column('data', sa.BLOB(), nullable=True),
    sa.Column('expiry', sa.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('session_id')
    )
    with op.batch_alter_table('tasks', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sa.NUMERIC(precision=16),
               type_=sqlalchemy_utils.types.uuid.UUIDType(),
               existing_nullable=False)

    with op.batch_alter_table('templates', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sa.NUMERIC(precision=16),
               type_=sqlalchemy_utils.types.uuid.UUIDType(),
               existing_nullable=False)

    with op.batch_alter_table('user', schema=None) as batch_op:
        batch_op.add_column(sa.Column('task_ids', sa.JSON(), nullable=True))
        batch_op.alter_column('id',
               existing_type=sa.NUMERIC(precision=16),
               type_=sqlalchemy_utils.types.uuid.UUIDType(),
               existing_nullable=False)
        batch_op.create_unique_constraint('task_ids', ['task_ids'])
        try:
            batch_op.drop_column('password_hash')
        except Exception:
            pass


    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('user', schema=None) as batch_op:
        #batch_op.add_column(sa.Column('password_hash', sa.VARCHAR(length=100), nullable=True))
        batch_op.drop_constraint(None, type_='unique')
        batch_op.alter_column('id',
               existing_type=sqlalchemy_utils.types.uuid.UUIDType(),
               type_=sa.NUMERIC(precision=16),
               existing_nullable=False)
        batch_op.drop_column('task_ids')

    with op.batch_alter_table('templates', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sqlalchemy_utils.types.uuid.UUIDType(),
               type_=sa.NUMERIC(precision=16),
               existing_nullable=False)

    with op.batch_alter_table('tasks', schema=None) as batch_op:
        batch_op.alter_column('id',
               existing_type=sqlalchemy_utils.types.uuid.UUIDType(),
               type_=sa.NUMERIC(precision=16),
               existing_nullable=False)

    op.create_table('sessions',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('session_id', sa.VARCHAR(length=255), nullable=True),
    sa.Column('data', sa.BLOB(), nullable=True),
    sa.Column('expiry', sa.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('session_id')
    )
    # ### end Alembic commands ###
