"""Add waiting_approval column to job table

Revision ID: add_waiting_approval
Revises: af3faaa3844c
Create Date: 2025-03-12 14:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'add_waiting_approval'
down_revision = 'af3faaa3844c'
branch_labels = None
depends_on = None


def upgrade():
    # Füge die neue Spalte waiting_approval zur job-Tabelle hinzu
    with op.batch_alter_table('job', schema=None) as batch_op:
        batch_op.add_column(sa.Column('waiting_approval', sa.Integer(), server_default='0', nullable=False))
    
    # SQLite-kompatible Migration für die print_job-Tabelle, falls diese existiert
    try:
        with op.batch_alter_table('print_job', schema=None) as batch_op:
            batch_op.add_column(sa.Column('waiting_approval', sa.Boolean(), server_default='0', nullable=False))
    except Exception as e:
        print(f"Migration für print_job-Tabelle übersprungen: {e}")


def downgrade():
    # Entferne die waiting_approval-Spalte aus der job-Tabelle
    with op.batch_alter_table('job', schema=None) as batch_op:
        batch_op.drop_column('waiting_approval')
    
    # SQLite-kompatible Migration für die print_job-Tabelle, falls diese existiert
    try:
        with op.batch_alter_table('print_job', schema=None) as batch_op:
            batch_op.drop_column('waiting_approval')
    except Exception as e:
        print(f"Downgrade für print_job-Tabelle übersprungen: {e}")