"""Add worker_configs table for dynamic concurrency settings.

Revision ID: 054
Revises: 053
"""
from alembic import op
import sqlalchemy as sa

revision = "054"
down_revision = "053"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "worker_configs",
        sa.Column("queue_name", sa.String(100), primary_key=True),
        sa.Column("max_concurrency", sa.Integer, nullable=False, server_default="8"),
        sa.Column("min_concurrency", sa.Integer, nullable=False, server_default="2"),
        sa.Column("enabled", sa.Boolean, nullable=False, server_default="true"),
        sa.Column("updated_at", sa.DateTime, nullable=False, server_default=sa.text("now()")),
    )
    # Seed default rows
    op.execute("""
        INSERT INTO worker_configs (queue_name, max_concurrency, min_concurrency, enabled)
        VALUES
            ('step_processing', 8, 2, true),
            ('asset_pipeline', 1, 1, true),
            ('ai_validation', 4, 1, true)
        ON CONFLICT DO NOTHING
    """)


def downgrade() -> None:
    op.drop_table("worker_configs")
