"""下线签到膨胀:drop signin_boost_record

产品 2026-07 确认「固定 3000 金币的签到膨胀」从来不是设计内的口径 —— 奖励只有「签到」和
「看视频」两种。签到弹窗里的「看广告膨胀」改与福利页看视频走同一条 reward_video 路径
(按 eCPM 公式发,记在 ad_reward_record),signin_boost 场景整体摘除。

⚠️ **只 drop 这张表,不动 coin_transaction**:`biz_type='signin_boost'` 的金币流水是真发过的
钱,账必须留得住(admin 大盘的 signin_boost_coin_total / signin_boost_watch_count 改为从
coin_transaction 统计,继续能查回历史)。本表只是「哪天膨胀过」的业务留痕,金额与去向都能
从流水还原,drop 掉不影响对账。

downgrade 只重建空表结构,**不恢复数据** —— 真要回滚得先从备份捞行。

Revision ID: drop_signin_boost_record
Revises: ad_reward_boost_round_id
Create Date: 2026-07-20
"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

revision: str = "drop_signin_boost_record"
down_revision: str | Sequence[str] | None = "ad_reward_boost_round_id"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    with op.batch_alter_table("signin_boost_record", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_signin_boost_record_user_id"))
    op.drop_table("signin_boost_record")


def downgrade() -> None:
    # 只还结构不还数据(见模块 docstring)
    op.create_table(
        "signin_boost_record",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("signin_date", sa.Date(), nullable=False),
        sa.Column("coin_awarded", sa.Integer(), nullable=False),
        sa.Column("ad_ref_id", sa.String(length=64), nullable=True),
        sa.Column(
            "created_at", sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False,
        ),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"]),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("user_id", "signin_date", name="uq_signin_boost_user_date"),
    )
    with op.batch_alter_table("signin_boost_record", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_signin_boost_record_user_id"), ["user_id"], unique=False
        )
