"""held_ticket_submit_order_flag

Revision ID: af3a34c8a412
Revises: aa5a157c371a
Create Date: 2021-06-08 13:23:30.589000

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


# revision identifiers, used by Alembic.
revision = 'af3a34c8a412'
down_revision = 'aa5a157c371a'
branch_labels = None
depends_on = None

first_agent_version = '21.6.21'


def upgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')
        connection.execute(
            "ALTER TABLE held_tickets ADD is_submit_order BOOLEAN DEFAULT '0' NOT NULL CHECK (is_submit_order in (0, 1))"
        )
    finally:
        connection.execute('PRAGMA foreign_keys = "1";')


def downgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')
        connection.execute('ALTER TABLE held_tickets DROP COLUMN is_submit_order;')
    finally:
        connection.execute('PRAGMA foreign_keys = "1";')
