"""Doris migration: create web_html_raw warehouse table.

Stores raw fetched HTML from the web crawler pipeline.  Uses UNIQUE KEY
on a UUID ``id`` column — every fetch creates a new row with a unique
identifier, preserving every fetch for auditability.
"""

from __future__ import annotations

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

VERSION = "0007"


def get_doris_migrations() -> list[Migration]:
    """Return ordered Doris migrations."""
    return [

        Migration(
            version="web_html_raw_doris_0001",
            description="Create web_html_raw warehouse table for raw fetched HTML",
            dialect="doris",
            up=(
                MigrationBuilder("web_html_raw", dialect="doris")
                .uuid("id", nullable=False)
                .varchar("seed_id", 64, nullable=False)
                .text("url", nullable=False)
                .text("raw_html", nullable=True)
                .integer("status_code", nullable=True)
                .jsonb("headers", nullable=True)
                .integer("depth", nullable=True, default=0)
                .varchar("fetched_at", 64, nullable=True)
                .bigint("created_at", nullable=True)
                .doris_unique_key(["id"])
                .doris_distributed_by("id", buckets=16)
                .create_table()
            ),
            down=MigrationBuilder("web_html_raw", dialect="doris").drop_table(),
        ),

    ]
