"""create material_cost table

Revision ID: 159b52ae3a59
Revises: 906b205a5a40
Create Date: 2026-06-12 16:04:20.512144
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


revision: str = '159b52ae3a59'
down_revision: Union[str, None] = '906b205a5a40'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table('material_cost',
    sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False, comment='主键'),
    sa.Column('oauth_id', sa.String(length=64), nullable=False, comment='授权表user_oauth自增id'),
    sa.Column('advertiser_id', sa.String(length=64), nullable=True, comment='广告主id'),
    sa.Column('material_id', sa.String(length=64), nullable=True, comment='素材id'),
    sa.Column('consume_date', sa.Date(), nullable=False, comment='消耗日期'),
    sa.Column('stat_cost', sa.Float(), nullable=True, comment='消耗金额'),
    sa.Column('show_cnt', sa.BigInteger(), nullable=True, comment='展示数'),
    sa.Column('cpm_platform', sa.Float(), nullable=True, comment='平均千次展现费用(元)'),
    sa.Column('click_cnt', sa.BigInteger(), nullable=True, comment='点击数'),
    sa.Column('ctr', sa.Float(), nullable=True, comment='点击率'),
    sa.Column('cpc_platform', sa.Float(), nullable=True, comment='平均点击单价(元)'),
    sa.Column('convert_cnt', sa.BigInteger(), nullable=True, comment='转化数'),
    sa.Column('conversion_cost', sa.Float(), nullable=True, comment='平均转化成本(元)'),
    sa.Column('conversion_rate', sa.Float(), nullable=True, comment='转化率'),
    sa.Column('deep_convert_cnt', sa.BigInteger(), nullable=True, comment='深度转化数'),
    sa.Column('deep_convert_cost', sa.Float(), nullable=True, comment='深度转化成本(元)'),
    sa.Column('deep_convert_rate', sa.Float(), nullable=True, comment='深度转化率'),
    sa.Column('active', sa.BigInteger(), nullable=True, comment='激活数'),
    sa.Column('active_cost', sa.Float(), nullable=True, comment='激活成本(元)'),
    sa.Column('active_rate', sa.Float(), nullable=True, comment='激活率'),
    sa.Column('active_register', sa.BigInteger(), nullable=True, comment='注册数'),
    sa.Column('active_register_cost', sa.Float(), nullable=True, comment='注册成本(元)'),
    sa.Column('active_register_rate', sa.Float(), nullable=True, comment='注册率'),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_material_cost_advertiser_id'), 'material_cost', ['advertiser_id'], unique=False)
    op.create_index(op.f('ix_material_cost_consume_date'), 'material_cost', ['consume_date'], unique=False)
    op.create_index(op.f('ix_material_cost_deleted_at'), 'material_cost', ['deleted_at'], unique=False)
    op.create_index(op.f('ix_material_cost_material_id'), 'material_cost', ['material_id'], unique=False)
    op.create_index(op.f('ix_material_cost_oauth_id'), 'material_cost', ['oauth_id'], unique=False)


def downgrade() -> None:
    op.drop_index(op.f('ix_material_cost_oauth_id'), table_name='material_cost')
    op.drop_index(op.f('ix_material_cost_material_id'), table_name='material_cost')
    op.drop_index(op.f('ix_material_cost_deleted_at'), table_name='material_cost')
    op.drop_index(op.f('ix_material_cost_consume_date'), table_name='material_cost')
    op.drop_index(op.f('ix_material_cost_advertiser_id'), table_name='material_cost')
    op.drop_table('material_cost')