"""ad_feed_reward_record.trace_id (比价看广告金币归属到比价记录)

Revision ID: ad_feed_reward_trace_id
Revises: device_kill_alert_pending
Create Date: 2026-06-21

比价等候期信息流广告(feed_ad_reward)结算时,客户端带上本场比价 trace_id 落此列;
比价记录页按 trace_id 聚合本场实发金币,显示「比价赚 N 金币」。领券/福利/旧客户端 = NULL。
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'ad_feed_reward_trace_id'
down_revision: Union[str, Sequence[str], None] = 'device_kill_alert_pending'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # SQLite 下 ADD COLUMN(可空) 与 CREATE INDEX 均原生支持,无需 batch_alter_table。
    op.add_column(
        'ad_feed_reward_record',
        sa.Column('trace_id', sa.String(length=64), nullable=True),
    )
    op.create_index(
        op.f('ix_ad_feed_reward_record_trace_id'),
        'ad_feed_reward_record',
        ['trace_id'],
        unique=False,
    )


def downgrade() -> None:
    op.drop_index(
        op.f('ix_ad_feed_reward_record_trace_id'),
        table_name='ad_feed_reward_record',
    )
    op.drop_column('ad_feed_reward_record', 'trace_id')
