"""held_item_order_mode_id

Revision ID: 3433a9867b15
Revises: db875614d5cf
Create Date: 2020-03-31 15:05:13.296000

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


# revision identifiers, used by Alembic.
revision = '3433a9867b15'
down_revision = 'db875614d5cf'
branch_labels = None
depends_on = None

first_agent_version = '20.3.31'


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

        with op.batch_alter_table('held_ticket_items') as batch_op:
            batch_op.add_column(Column('item_order_mode_id', String(length=64), nullable=True))
    except:
        # skip, it already exists.
        pass
    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('held_ticket_items') as batch_op:
            batch_op.drop_column('item_order_mode_id')
    except:
        # skip, it already exists.
        pass
    finally:
        connection.execute('PRAGMA foreign_keys = "1";')