"""add publishing scenario runs to agents

Revision ID: 93647ca77971
Revises: 83647ca77970
Create Date: 2026-06-02 12:00:00.000000
"""

import os
import sys
from collections.abc import Sequence

import sqlalchemy as sa

# Add alembic folder to path for utils import
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils import JsonEncoded, batch_alter_table, migration_logger as logger
from utils import table_exists as _table_exists

revision: str = "93647ca77971"
down_revision: str | Sequence[str] | None = "83647ca77970"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add scenario run tracking for publishing."""
    if not _table_exists("agents"):
        logger.warning("agents table not found; skipping publishing_scenario_runs migration")
        return

    with batch_alter_table("agents") as batch_op:
        batch_op.add_column(sa.Column("publishing_scenario_runs", JsonEncoded(), nullable=True))


def downgrade() -> None:
    """Remove scenario run tracking for publishing."""
    if not _table_exists("agents"):
        logger.warning("agents table not found; skipping publishing_scenario_runs downgrade")
        return

    with batch_alter_table("agents") as batch_op:
        batch_op.drop_column("publishing_scenario_runs")
