"""Add container_metadata_json column to tool_invocations table.

Revision ID: m6_004_container_metadata_column
Revises: m6_004_resource_type_inherits
Create Date: 2026-03-11 00:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

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


def upgrade() -> None:
    """Add container_metadata_json column for container execution audit trail."""
    with op.batch_alter_table("tool_invocations") as batch_op:
        batch_op.add_column(
            sa.Column("container_metadata_json", sa.Text(), nullable=True),
        )


def downgrade() -> None:
    """Remove container_metadata_json column."""
    with op.batch_alter_table("tool_invocations") as batch_op:
        batch_op.drop_column("container_metadata_json")
