"""ad_reward_record table (看激励视频发奖记录)

Revision ID: c8d9e0f1a2b3
Revises: b1c2d3e4f5a6
Create Date: 2026-05-26 10:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    op.create_table(
        'ad_reward_record',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('trans_id', sa.String(length=64), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('coin', sa.Integer(), nullable=False),
        sa.Column('status', sa.String(length=16), nullable=False),
        sa.Column('reward_date', sa.String(length=10), nullable=False),
        sa.Column('reward_name', sa.String(length=64), nullable=True),
        sa.Column('raw', sa.String(length=1024), 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'),
    )
    with op.batch_alter_table('ad_reward_record', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_ad_reward_record_trans_id'), ['trans_id'], unique=True)
        batch_op.create_index(batch_op.f('ix_ad_reward_record_user_id'), ['user_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_ad_reward_record_reward_date'), ['reward_date'], unique=False)
        batch_op.create_index(batch_op.f('ix_ad_reward_record_created_at'), ['created_at'], unique=False)


def downgrade() -> None:
    with op.batch_alter_table('ad_reward_record', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_ad_reward_record_created_at'))
        batch_op.drop_index(batch_op.f('ix_ad_reward_record_reward_date'))
        batch_op.drop_index(batch_op.f('ix_ad_reward_record_user_id'))
        batch_op.drop_index(batch_op.f('ix_ad_reward_record_trans_id'))

    op.drop_table('ad_reward_record')
