"""Add inherits column to resource_types for type inheritance (ADR-042).

Revision ID: m6_004_resource_type_inherits
Revises: m7_001_repo_indexing_tables
Create Date: 2026-03-06 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_resource_type_inherits"
down_revision: str | Sequence[str] | None = "m7_001_repo_indexing_tables"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add inherits column and index to resource_types."""
    op.add_column(
        "resource_types",
        sa.Column("inherits", sa.String(255), nullable=True),
    )
    op.create_index(
        "ix_resource_types_inherits",
        "resource_types",
        ["inherits"],
        if_not_exists=True,
    )


def downgrade() -> None:
    """Remove inherits column and index from resource_types."""
    op.drop_index("ix_resource_types_inherits", table_name="resource_types")
    op.drop_column("resource_types", "inherits")
