"""Telegram per-user digest preferences. Adds three columns to telegram_bindings so each subscriber can opt in/out of the daily three-section brief (Macro Vibes / KOL / Trump) and pick which UTC hour it lands. digest_enabled : bool, default True. Toggleable via /digest on|off. digest_hour_utc : int 0–23, default 12. Toggleable via /digest_time HH. 12 UTC ≈ Asia evening / EU afternoon / US morning — the only single hour that's reasonable for all three big crypto-active zones, so it's our default. last_digest_sent_at : nullable timestamp. Guards against double-send if the cron coalesces or the worker restarts mid-firing. Used as "skip if < 23h ago" in send_daily_digest. Backfills are safe: every existing binding gets digest_enabled=True so users who subscribed before this feature start receiving the brief automatically. If they don't want it, one /digest off keeps them off. Revision ID: 023 Revises: 022 Create Date: 2026-05-26 """ from alembic import op import sqlalchemy as sa revision = "023" down_revision = "022" branch_labels = None depends_on = None def upgrade() -> None: with op.batch_alter_table("telegram_bindings") as batch: batch.add_column(sa.Column( "digest_enabled", sa.Boolean, nullable=False, server_default=sa.true(), )) batch.add_column(sa.Column( "digest_hour_utc", sa.Integer, nullable=False, server_default="12", )) batch.add_column(sa.Column( "last_digest_sent_at", sa.DateTime, nullable=True, )) def downgrade() -> None: with op.batch_alter_table("telegram_bindings") as batch: batch.drop_column("last_digest_sent_at") batch.drop_column("digest_hour_utc") batch.drop_column("digest_enabled")