"""void types

Revision ID: 735393a229d9
Revises: 3bb222243bc9
Create Date: 2018-03-05 09:04:34.138000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '735393a229d9'
down_revision = '3bb222243bc9'
branch_labels = None
depends_on = None

first_agent_version = '18.3.6'


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('held_ticket_items', schema=None) as batch_op:
            batch_op.add_column(sa.Column('approving_employee_id', sa.Integer(), nullable=True))
            batch_op.add_column(sa.Column('void_type_id', sa.Integer(), nullable=True))

        with op.batch_alter_table('ticket_items', schema=None) as batch_op:
            batch_op.add_column(sa.Column('approving_employee_id', sa.Integer(), nullable=True))
            batch_op.add_column(sa.Column('void_type_id', sa.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('ticket_items', schema=None) as batch_op:
            batch_op.drop_column('void_type_id')
            batch_op.drop_column('approving_employee_id')

        with op.batch_alter_table('held_ticket_items', schema=None) as batch_op:
            batch_op.drop_column('void_type_id')
            batch_op.drop_column('approving_employee_id')

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