"""Add safety_json and guards_json columns to automation_profiles table.

Persists the full SafetyProfile and AutomationGuard sub-models as
serialised JSON, complementing the existing scalar safety columns.
Nullable so existing rows are unaffected.

Revision ID: m6_005_profile_guards_json
Revises: m6_004_container_metadata_column
Create Date: 2026-03-13 00:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

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


def upgrade() -> None:
    """Add safety_json and guards_json columns to automation_profiles."""
    with op.batch_alter_table("automation_profiles") as batch_op:
        batch_op.add_column(
            sa.Column("safety_json", sa.Text(), nullable=True),
        )
        batch_op.add_column(
            sa.Column("guards_json", sa.Text(), nullable=True),
        )


def downgrade() -> None:
    """Remove safety_json and guards_json columns."""
    with op.batch_alter_table("automation_profiles") as batch_op:
        batch_op.drop_column("guards_json")
        batch_op.drop_column("safety_json")
