"""Add media download fields to ``telegram_crawl_metrics`` warehouse table.

Adds two columns to the existing ``telegram_crawl_metrics`` table so that
tele-media worker download timing can be stored alongside crawl pipeline
metrics in a single row per message.  For messages without media these
columns remain ``NULL``.

Supersedes the standalone ``telegram_media_download_metrics`` table that
was created by migration ``0004`` (now deactivated).
"""

from __future__ import annotations

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

VERSION = "0005"


def get_doris_migrations() -> list[Migration]:
    """Return Doris warehouse migration adding media fields to crawl metrics."""
    return [
        Migration(
            version="crawl_metric_media_doris_0005",
            description="Add downloaded_at + download_duration to telegram_crawl_metrics",
            dialect="doris",
            up=(
                MigrationBuilder("telegram_crawl_metrics", dialect="doris")
                .add_column("downloaded_at", "DATETIME", nullable=True)
                .add_column("download_duration", "BIGINT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("telegram_crawl_metrics", dialect="doris")
                .drop_column("download_duration")
                .drop_column("downloaded_at")
                .alter_table()
            ),
        ),
    ]
