"""add_item_order_mode_id_to_ticket_items

Revision ID: c399658b0b3b
Revises: a0b8a3c20bbd
Create Date: 2020-02-13 14:12:36.493000

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


# revision identifiers, used by Alembic.
revision = 'c399658b0b3b'
down_revision = 'a0b8a3c20bbd'
branch_labels = None
depends_on = None

first_agent_version = '20.3.4'


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

        with op.batch_alter_table('ticket_items') as batch_op:
            batch_op.add_column(Column('item_order_mode_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_items') as batch_op:
            batch_op.drop_column('item_order_mode_id')

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