"""Add raw_hash and version columns to ``web_html_raw`` warehouse table.

- ``raw_hash``: SHA-256 hex digest of the HTML content (64 chars)
- ``version``: monotonically increasing version counter per URL (INT, default 1)

Together these enable content-change detection and versioned history
in the persistence layer — when content is unchanged on revisit, no
new row is inserted.

Revision ID: 0016
"""
from __future__ import annotations

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

VERSION = "0016"


def get_doris_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_html_raw_hash_version_0001",
            description="Add raw_hash and version columns to web_html_raw",
            dialect="doris",
            up=(
                MigrationBuilder("web_html_raw", dialect="doris")
                .add_column("raw_hash", "VARCHAR(64)", nullable=True)
                .add_column("version", "INT", nullable=True, default=1)
                .alter_table()
            ),
            down=(
                MigrationBuilder("web_html_raw", dialect="doris")
                .drop_column("raw_hash")
                .drop_column("version")
                .alter_table()
            ),
        ),
    ]
