"""Add bounded execution output events for curation jobs.""" from collections.abc import Sequence import sqlalchemy as sa from alembic import op revision: str = "20260806_0011" down_revision: str | Sequence[str] | None = "20260805_0010" branch_labels: str | Sequence[str] | None = None depends_on: str | Sequence[str] | None = None def upgrade() -> None: op.create_table( "curation_execution_events", sa.Column("sequence", sa.Integer(), autoincrement=True, nullable=False), sa.Column("job_id", sa.String(length=36), nullable=False), sa.Column("attempt_id", sa.String(length=36), nullable=True), sa.Column("phase", sa.String(length=32), nullable=False), sa.Column("level", sa.String(length=16), nullable=False, server_default="info"), sa.Column("message_code", sa.String(length=80), nullable=False), sa.Column("details_json", sa.Text(), nullable=False, server_default="{}"), sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint(["attempt_id"], ["curation_attempts.id"], ondelete="SET NULL"), sa.ForeignKeyConstraint(["job_id"], ["curation_jobs.id"], ondelete="CASCADE"), sa.PrimaryKeyConstraint("sequence"), ) op.create_index( "ix_curation_execution_events_job_id", "curation_execution_events", ["job_id"], unique=False, ) op.create_index( "ix_curation_execution_events_attempt_id", "curation_execution_events", ["attempt_id"], unique=False, ) op.create_index( "ix_curation_execution_events_phase", "curation_execution_events", ["phase"], unique=False, ) op.create_index( "ix_curation_execution_events_job_created", "curation_execution_events", ["job_id", "created_at"], unique=False, ) def downgrade() -> None: op.drop_index( "ix_curation_execution_events_job_created", table_name="curation_execution_events", ) op.drop_index("ix_curation_execution_events_phase", table_name="curation_execution_events") op.drop_index("ix_curation_execution_events_attempt_id", table_name="curation_execution_events") op.drop_index("ix_curation_execution_events_job_id", table_name="curation_execution_events") op.drop_table("curation_execution_events")