"""ticket item seats

Revision ID: 7f3a6c94e57e
Revises: 281cea12023f

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


# revision identifiers, used by Alembic.
revision = '7f3a6c94e57e'
down_revision = '1329d9147b45'
branch_labels = None
depends_on = None

first_agent_version = '19.10.7'


def upgrade():
    """
    Use batch-operations to support sqlite

    > with op.batch_alter_table('table_name') as batch_op:
    >     pass
    """

    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('seat', Integer(), nullable=True))

        with op.batch_alter_table('held_ticket_items') as batch_op:
            batch_op.add_column(Column('seat', Integer(), nullable=True))

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


def downgrade():
    """
    Use batch-operations to support sqlite

    > with op.batch_alter_table('table_name') as batch_op:
    >     pass
    """

    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('seat')

        with op.batch_alter_table('ticket_items') as batch_op:
            batch_op.drop_column('seat')

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