"""Create ``web_metrics`` warehouse table for per-media operational telemetry.

Revision ID: 0013
"""
from __future__ import annotations

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

VERSION = "0013"


def get_doris_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_metrics_doris_0001",
            description="Create web_metrics table for per-media download telemetry",
            dialect="doris",
            up=(
                MigrationBuilder("web_metrics", dialect="doris")
                .varchar("source_url", 2048, nullable=False)
                .varchar("seed_id", 64, nullable=False)
                .text("media_type", nullable=False)
                .text("status", nullable=False)
                .text("content_type", nullable=True)
                .bigint("content_length", nullable=True)
                .integer("download_duration_ms", nullable=True)
                .integer("upload_duration_ms", nullable=True)
                .integer("total_duration_ms", nullable=True)
                .text("error_message", nullable=True)
                .varchar("downloaded_at", 64, nullable=True)
                .varchar("created_at", 64, nullable=True)
                .doris_duplicate_key(["source_url"])
                .doris_distributed_by("source_url", buckets=16)
                .create_table()
            ),
            down=MigrationBuilder("web_metrics", dialect="doris").drop_table(),
        ),
    ]
