"""add_kitchen_completed_at
Revision ID: 3ced2f231be1
Revises: 4ff085c3804a
Create Date: 2025-05-13 15:39:14.844000
"""
from alembic import op
from sqlalchemy import (
    Column,
    DateTime,
)


# revision identifiers, used by Alembic.
revision = '3ced2f231be1'
down_revision = '4ff085c3804a'
branch_labels = None
depends_on = None

# TODO: Set the first_agent_version correctly before merging this revision
first_agent_version = '25.5.14'


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

        with op.batch_alter_table('tickets') as batch_op:
            batch_op.add_column(Column('kitchen_completed_at', DateTime, nullable=True))

        with op.batch_alter_table('held_tickets') as batch_op:
            batch_op.add_column(Column('kitchen_completed_at', DateTime, 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('tickets') as batch_op:
            batch_op.drop_column('kitchen_completed_at')

        with op.batch_alter_table('held_tickets') as batch_op:
            batch_op.drop_column('kitchen_completed_at')

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