"""Two new codegen_runs.status values: a primitive_gap (or blocked pack install) must
not let a run finalize as plain 'completed' -- that's the same label as a run with
nothing missing, which is a semantic lie once a required capability wasn't fulfilled.

- 'blocked': a *required* requirement was unresolved (primitive_gap or a blocked pack
  install). Describes the capability's status, not that the run was prevented from
  shipping -- by the time composition resolves, the code has already been committed
  and pushed (see src/workers/tasks/codegen.py's _select_final_status docstring).
- 'completed_with_limitations': only *optional* requirements were unresolved; the run
  otherwise delivered everything required.

Revision ID: 129
Revises: 128
"""
from alembic import op
import sqlalchemy as sa

revision = "129"
down_revision = "128"
branch_labels = None
depends_on = None


def upgrade() -> None:
    bind = op.get_bind()
    ctx = op.get_context()

    # PostgreSQL requires newly added enum values to be committed
    # before they are referenced in DML (same requirement as migration 026).
    with ctx.autocommit_block():
        bind.execute(
            sa.text(
                "ALTER TYPE p2hs_codegen_run_status "
                "ADD VALUE IF NOT EXISTS 'completed_with_limitations'"
            )
        )
        bind.execute(
            sa.text(
                "ALTER TYPE p2hs_codegen_run_status "
                "ADD VALUE IF NOT EXISTS 'blocked'"
            )
        )
