"""Add deleted_at column to telegram_channels for soft-delete support.

Previously, deleting a channel hard-removed the row from PostgreSQL,
which meant dashboards and analytics could no longer resolve the
channel's title/username — showing only a raw numeric ID.

With ``deleted_at``, the row is preserved.  The label resolver in the
telemetry service includes soft-deleted channels and appends "🗑 removed"
to the label.  List queries filter ``WHERE deleted_at IS NULL`` by default.
"""

from __future__ import annotations

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

VERSION = "0010"


def get_postgres_migrations() -> list[Migration]:
    """Return ordered PostgreSQL migrations."""

    return [
        Migration(
            version="tg_channel_soft_delete",
            description=(
                "Add deleted_at timestamp to telegram_channels "
                "for soft-deletion support (preserve labels for dashboards)"
            ),
            up=(
                MigrationBuilder("telegram_channels")
                .add_column("deleted_at", "TIMESTAMP WITH TIME ZONE", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("telegram_channels")
                .drop_column("deleted_at")
                .alter_table()
            ),
        ),
    ]
