"""coin reward points phase2

Revision ID: coin_reward_phase2
Revises: 0cf18d590b1d
Create Date: 2026-06-08
"""

from __future__ import annotations

from alembic import op
import sqlalchemy as sa


revision = "coin_reward_phase2"
down_revision = "0cf18d590b1d"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "ad_ecpm_record",
        sa.Column("ad_session_id", sa.String(length=64), nullable=True),
    )
    op.create_index(
        op.f("ix_ad_ecpm_record_ad_session_id"),
        "ad_ecpm_record",
        ["ad_session_id"],
        unique=False,
    )
    op.create_index(
        "uq_ad_ecpm_record_session",
        "ad_ecpm_record",
        ["ad_session_id"],
        unique=True,
    )

    op.add_column(
        "ad_reward_record",
        sa.Column(
            "reward_scene",
            sa.String(length=32),
            nullable=False,
            server_default="reward_video",
        ),
    )
    op.add_column(
        "ad_reward_record",
        sa.Column("ad_session_id", sa.String(length=64), nullable=True),
    )
    op.add_column(
        "ad_reward_record",
        sa.Column("ecpm_raw", sa.String(length=32), nullable=True),
    )
    op.create_index(
        op.f("ix_ad_reward_record_ad_session_id"),
        "ad_reward_record",
        ["ad_session_id"],
        unique=False,
    )


def downgrade() -> None:
    op.drop_index(op.f("ix_ad_reward_record_ad_session_id"), table_name="ad_reward_record")
    op.drop_column("ad_reward_record", "ecpm_raw")
    op.drop_column("ad_reward_record", "ad_session_id")
    op.drop_column("ad_reward_record", "reward_scene")

    op.drop_index("uq_ad_ecpm_record_session", table_name="ad_ecpm_record")
    op.drop_index(op.f("ix_ad_ecpm_record_ad_session_id"), table_name="ad_ecpm_record")
    op.drop_column("ad_ecpm_record", "ad_session_id")
