"""add_modifier_group_id_to_ticket_item_modifier

Revision ID: 4ff085c3804a
Revises: dc2a1fb619b9
Create Date: 2022-07-15 08:11:57.375000

"""
from alembic import op
from sqlalchemy import Column, String


# revision identifiers, used by Alembic.
revision = '4ff085c3804a'
down_revision = 'dc2a1fb619b9'
branch_labels = None
depends_on = None

first_agent_version = '22.8.12'


def upgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('ticket_item_modifiers') as batch_op:
            batch_op.add_column(
                Column('menu_modifier_group_id', String(length=64), nullable=True)
            )

        with op.batch_alter_table('held_ticket_item_modifiers') as batch_op:
            batch_op.add_column(
                Column('menu_modifier_group_id', String(length=64), nullable=True)
            )

    finally:
        connection.execute('PRAGMA foreign_keys = "1";')


def downgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('ticket_item_modifiers') as batch_op:
            batch_op.drop_column('menu_modifier_group_id')

        with op.batch_alter_table('held_ticket_item_modifiers') as batch_op:
            batch_op.drop_column('menu_modifier_group_id')

    finally:
        connection.execute('PRAGMA foreign_keys = "1";')
