"""Add ``raw_hash`` column to ``codal_statements``. Revision ID: 0027"""

from __future__ import annotations

from repo_core.migrations.builder import MigrationBuilder
from repo_core.migrations.runner import Migration

VERSION = "0027"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_statements_0007",
            description="Add raw_hash column to codal_statements for version detection",
            up=(
                MigrationBuilder("codal_statements")
                .add_column("raw_hash", "TEXT", nullable=True)
                .add_index(["url", "raw_hash"])
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_statements")
                .drop_index("ix_codal_statements_url_raw_hash")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
    ]
