"""Form history

Revision ID: 1a55b7674144
Revises: e664a2f70952
Create Date: 2023-01-02 09:41:58.716218

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1a55b7674144'
down_revision = 'e664a2f70952'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('form_history',
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('form_id', sa.String(), nullable=False),
    sa.Column('parent_form_id', sa.String(), nullable=False),
    sa.Column('created_by', sa.String(), nullable=False),
    sa.Column('change_log', sa.JSON(), nullable=False),
    sa.Column('workflow', sa.Boolean(), nullable=True),
    sa.Column('title', sa.Boolean(), nullable=True),
    sa.Column('component_change', sa.Boolean(), nullable=True),
    sa.Column('anonymous', sa.Boolean(), nullable=True),
    sa.Column('status', sa.Boolean(), nullable=True),
    sa.Column('form_type', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_form_history_form_id'), 'form_history', ['form_id'], unique=False)
    op.add_column('form_process_mapper', sa.Column('form_type', sa.String(length=20), nullable=True))
    op.execute("update form_process_mapper set form_type = 'form' where form_process_mapper.form_type is null or form_process_mapper.form_type = ''")
    op.alter_column('form_process_mapper', 'form_type', nullable=False)
    op.add_column('form_process_mapper', sa.Column('parent_form_id', sa.String(length=50), nullable=True))
    op.execute("update form_process_mapper set parent_form_id = form_process_mapper.form_id where form_process_mapper.parent_form_id is null or form_process_mapper.parent_form_id = ''")
    op.alter_column('form_process_mapper', 'parent_form_id', nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('form_process_mapper', 'parent_form_id')
    op.drop_column('form_process_mapper', 'form_type')
    op.drop_index(op.f('ix_form_history_parent_form_id'), table_name='form_history')
    op.drop_index(op.f('ix_form_history_form_id'), table_name='form_history')
    op.drop_table('form_history')
    # ### end Alembic commands ###
