"""ad_ecpm_record table (广告展示 eCPM 上报记录,内部收益统计/对账)

Revision ID: a1b2c3d4e5f6
Revises: f01db5d77dac
Create Date: 2026-05-31 11:30:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    op.create_table(
        'ad_ecpm_record',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('ad_type', sa.String(length=32), nullable=False),
        sa.Column('adn', sa.String(length=32), nullable=True),
        sa.Column('slot_id', sa.String(length=64), nullable=True),
        sa.Column('ecpm_raw', sa.String(length=32), nullable=False),
        sa.Column('report_date', sa.String(length=10), nullable=False),
        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_ecpm_record', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_ad_ecpm_record_user_id'), ['user_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_ad_ecpm_record_report_date'), ['report_date'], unique=False)
        batch_op.create_index(batch_op.f('ix_ad_ecpm_record_created_at'), ['created_at'], unique=False)


def downgrade() -> None:
    with op.batch_alter_table('ad_ecpm_record', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_ad_ecpm_record_created_at'))
        batch_op.drop_index(batch_op.f('ix_ad_ecpm_record_report_date'))
        batch_op.drop_index(batch_op.f('ix_ad_ecpm_record_user_id'))

    op.drop_table('ad_ecpm_record')
