"""Doris warehouse migration: add optional entity fields to telegram_message_details.

Adds ``url``, ``language``, ``user_id``, and ``document_id`` columns to the
``telegram_message_details`` DUPLICATE KEY table.  All four fields are nullable —
existing rows and consumers are unaffected.
"""

from __future__ import annotations

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

VERSION = "0002"


def get_doris_migrations() -> list[Migration]:
    """Return the ALTER migration for telegram_message_details extra fields."""
    return [
        Migration(
            version="msg_details_doris_0002",
            description=(
                "Add url, language, user_id, document_id columns to "
                "telegram_message_details"
            ),
            dialect="doris",
            up=(
                MigrationBuilder("telegram_message_details", dialect="doris")
                .add_column("url", "TEXT", nullable=True)
                .add_column("language", "VARCHAR(8)", nullable=True)
                .add_column("user_id", "BIGINT", nullable=True)
                .add_column("document_id", "BIGINT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("telegram_message_details", dialect="doris")
                .drop_column("url")
                .drop_column("language")
                .drop_column("user_id")
                .drop_column("document_id")
                .alter_table()
            ),
        ),
    ]
