"""Add execution_environment and execution_env_priority columns to v3_plans.

These columns persist the execution environment override and its priority
semantics (fallback vs override) set via ``agents plan use
--execution-environment`` and ``--execution-env-priority``.  Previously
these values were set on the in-memory Plan object but never persisted
to the database.

Revision ID: m4_003_plan_env_columns
Revises: m6_005_profile_guards_json
Create Date: 2026-03-16 00:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "m4_003_plan_env_columns"
down_revision: str | Sequence[str] | None = "m6_005_profile_guards_json"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add execution_environment and execution_env_priority to v3_plans."""
    with op.batch_alter_table("v3_plans") as batch_op:
        batch_op.add_column(
            sa.Column("execution_environment", sa.String(255), nullable=True),
        )
        batch_op.add_column(
            sa.Column("execution_env_priority", sa.String(20), nullable=True),
        )


def downgrade() -> None:
    """Remove execution_environment and execution_env_priority from v3_plans."""
    with op.batch_alter_table("v3_plans") as batch_op:
        batch_op.drop_column("execution_env_priority")
        batch_op.drop_column("execution_environment")
