"""Add yaml_text, schema_version, compiled_metadata to actors table.

Extends the ``actors`` table with columns needed by the aligned actor
registry persistence layer:

- ``yaml_text``: Original YAML source text for the actor definition.
- ``schema_version``: Version indicator for the persisted schema
  (defaults to ``'1.0'``).
- ``compiled_metadata``: JSON blob of metadata produced by the actor
  compiler pipeline.

Revision ID: c3_001_actor_registry
Revises: a7_002_merge_heads
Create Date: 2026-02-18 00:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

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


def upgrade() -> None:
    """Add registry persistence columns to actors table."""

    with op.batch_alter_table("actors") as batch_op:
        batch_op.add_column(sa.Column("yaml_text", sa.Text(), nullable=True))
        batch_op.add_column(
            sa.Column(
                "schema_version",
                sa.String(length=20),
                nullable=False,
                server_default="1.0",
            )
        )
        batch_op.add_column(sa.Column("compiled_metadata", sa.JSON(), nullable=True))


def downgrade() -> None:
    """Remove registry persistence columns from actors table."""

    with op.batch_alter_table("actors") as batch_op:
        batch_op.drop_column("compiled_metadata")
        batch_op.drop_column("schema_version")
        batch_op.drop_column("yaml_text")
