"""add continuous eval test table

Revision ID: 6939d74b3750
Revises: 04c5e8528072
Create Date: 2026-04-07 15:23:52.258690

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "6939d74b3750"
down_revision = "04c5e8528072"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "continuous_eval_test_runs",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("continuous_eval_id", sa.UUID(), nullable=False),
        sa.Column("task_id", sa.String(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("total_count", sa.Integer(), nullable=False),
        sa.Column("completed_count", sa.Integer(), nullable=False),
        sa.Column("passed_count", sa.Integer(), nullable=False),
        sa.Column("failed_count", sa.Integer(), nullable=False),
        sa.Column("error_count", sa.Integer(), nullable=False),
        sa.Column("skipped_count", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(), nullable=False),
        sa.Column("updated_at", sa.TIMESTAMP(), nullable=False),
        sa.ForeignKeyConstraint(
            ["continuous_eval_id"], ["continuous_evals.id"], ondelete="CASCADE"
        ),
        sa.ForeignKeyConstraint(
            ["task_id"],
            ["tasks.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_continuous_eval_test_runs_continuous_eval_id"),
        "continuous_eval_test_runs",
        ["continuous_eval_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_continuous_eval_test_runs_id"),
        "continuous_eval_test_runs",
        ["id"],
        unique=False,
    )
    op.add_column(
        "agentic_annotations", sa.Column("test_run_id", sa.UUID(), nullable=True)
    )
    op.create_index(
        op.f("ix_agentic_annotations_test_run_id"),
        "agentic_annotations",
        ["test_run_id"],
        unique=False,
    )
    op.create_foreign_key(
        "fk_agentic_annotations_test_run_id",
        "agentic_annotations",
        "continuous_eval_test_runs",
        ["test_run_id"],
        ["id"],
        ondelete="CASCADE",
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("fk_agentic_annotations_test_run_id", "agentic_annotations", type_="foreignkey")
    op.drop_index(
        op.f("ix_agentic_annotations_test_run_id"), table_name="agentic_annotations"
    )
    op.drop_column("agentic_annotations", "test_run_id")
    op.drop_index(
        op.f("ix_continuous_eval_test_runs_id"), table_name="continuous_eval_test_runs"
    )
    op.drop_index(
        op.f("ix_continuous_eval_test_runs_continuous_eval_id"),
        table_name="continuous_eval_test_runs",
    )
    op.drop_table("continuous_eval_test_runs")
    # ### end Alembic commands ###
