"""新增素材消耗表，新增资源素材绑定表，修改授权账户表授权id

Revision ID: acb510c75f6a
Revises: 159b52ae3a59
Create Date: 2026-06-12 17:03:27.447544
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    op.add_column('material_cost', sa.Column('attribution_next_day_open_cnt', sa.BigInteger(), nullable=True, comment='次留数'))
    op.add_column('material_cost', sa.Column('attribution_next_day_open_cost', sa.Float(), nullable=True, comment='次留成本'))
    op.add_column('material_cost', sa.Column('attribution_next_day_open_rate', sa.Float(), nullable=True, comment='次留率'))
    op.add_column('material_cost', sa.Column('active_pay', sa.BigInteger(), nullable=True, comment='首次付费数'))
    op.add_column('material_cost', sa.Column('active_pay_cost', sa.Float(), nullable=True, comment='首次付费成本(元)'))
    op.add_column('material_cost', sa.Column('active_pay_rate', sa.Float(), nullable=True, comment='首次付费率'))
    op.add_column('material_cost', sa.Column('phone', sa.BigInteger(), nullable=True, comment='点击电话按钮'))
    op.add_column('material_cost', sa.Column('form', sa.BigInteger(), nullable=True, comment='用户在门店落地页多线沟通提交表单的次数'))
    op.add_column('material_cost', sa.Column('download_start', sa.BigInteger(), nullable=True, comment='用户点击下载开始的次数'))
    op.add_column('material_cost', sa.Column('form_submit', sa.BigInteger(), nullable=True, comment='用户查看附加创意后，提交表单的次数'))
    op.add_column('material_cost', sa.Column('button', sa.BigInteger(), nullable=True, comment='用户点击按钮button的次数'))
    op.add_column('material_cost', sa.Column('view', sa.BigInteger(), nullable=True, comment='用户在关键页面的浏览次数'))
    op.add_column('material_cost', sa.Column('message', sa.BigInteger(), nullable=True, comment='用户点击短信咨询的次数'))
    op.add_column('material_cost', sa.Column('consult', sa.BigInteger(), nullable=True, comment='用户点击在线咨询按钮的次数'))
    op.add_column('material_cost', sa.Column('consult_effective', sa.BigInteger(), nullable=True, comment='用户在门店落地页多线沟通的在线咨询中有效咨询的次数'))
    op.add_column('material_cost', sa.Column('shopping', sa.BigInteger(), nullable=True, comment='用户购买商品的次数'))
    op.add_column('material_cost', sa.Column('customer_effective', sa.BigInteger(), nullable=True, comment='有效获客'))
    op.add_column('material_cost', sa.Column('attribution_game_in_app_ltv_1day', sa.Float(), nullable=True, comment='当日付费金额'))
    op.add_column('material_cost', sa.Column('attribution_game_in_app_roi_1day', sa.Float(), nullable=True, comment='当日付费ROI'))
    op.add_column('material_cost', sa.Column('loan_completion', sa.BigInteger(), nullable=True, comment='完件数互联网金融-贷款行业中，用户成功提交贷款额度申请的行为'))
    op.add_column('material_cost', sa.Column('loan_completion_cost', sa.Float(), nullable=True, comment='完件成本(元)'))
    op.add_column('material_cost', sa.Column('loan_completion_rate', sa.Float(), nullable=True, comment='完件率'))
    op.add_column('material_cost', sa.Column('loan_credit', sa.BigInteger(), nullable=True, comment='互联网金融-贷款行业中，用户提交贷款额度申请后，客户审批通过，给予用户可贷款的额度'))
    op.add_column('material_cost', sa.Column('loan_credit_cost', sa.Float(), nullable=True, comment='授信成本(元)'))
    op.add_column('material_cost', sa.Column('loan_credit_rate', sa.Float(), nullable=True, comment='授信率'))
    op.add_column('material_cost', sa.Column('in_app_order_gmv', sa.Float(), nullable=True, comment='当您使用"in_app_order"事件回传订单金额时，对应的GMV金额，引流电商订单GMV'))
    op.add_column('material_cost', sa.Column('in_app_order_roi', sa.Float(), nullable=True, comment='引流电商订单ROI'))
    op.add_column('material_cost', sa.Column('in_app_pay_gmv', sa.Float(), nullable=True, comment='引流电商支付GMV'))
    op.add_column('material_cost', sa.Column('in_app_pay_roi', sa.Float(), nullable=True, comment='引流电商支付ROI'))
    op.add_column('material_cost', sa.Column('total_play', sa.BigInteger(), nullable=True, comment='播放量播放时间大于0S的数量，在某些蜂窝网络环境下，需要您手动点击开始才会开始播放，因此有时播放数小于展示数。'))
    op.add_column('material_cost', sa.Column('valid_play', sa.BigInteger(), nullable=True, comment='有效播放数'))
    op.add_column('material_cost', sa.Column('valid_play_cost', sa.Float(), nullable=True, comment='有效播放成本(元)'))
    op.add_column('material_cost', sa.Column('valid_play_rate', sa.Float(), nullable=True, comment='有效播放率'))
    op.add_column('material_cost', sa.Column('valid_play_of_mille', sa.BigInteger(), nullable=True, comment='千次有效播放数'))
    op.add_column('material_cost', sa.Column('valid_play_cost_of_mille', sa.Float(), nullable=True, comment='千次有效播放成本(元)'))
    op.add_column('material_cost', sa.Column('average_play_time_per_play', sa.Float(), nullable=True, comment='平均单次播放时长'))
    op.add_column('material_cost', sa.Column('play_over_rate', sa.Float(), nullable=True, comment='完播率'))
    op.add_column('material_cost', sa.Column('dy_like', sa.BigInteger(), nullable=True, comment='点赞数'))
    op.add_column('material_cost', sa.Column('dy_comment', sa.BigInteger(), nullable=True, comment='评论量'))
    op.add_column('material_cost', sa.Column('dy_share', sa.BigInteger(), nullable=True, comment='分享量'))
    op.add_column('material_cost', sa.Column('report_cnt', sa.BigInteger(), nullable=True, comment='举报数'))
    op.add_column('user_oauth_account', sa.Column('oauth_id', sa.String(length=64), nullable=True, comment='授权表中的id'))
    op.execute('UPDATE user_oauth_account SET oauth_id = account_id WHERE oauth_id IS NULL')
    op.alter_column('user_oauth_account', 'oauth_id', nullable=False)
    op.alter_column('user_oauth_account', 'advertiser_id',
               existing_type=sa.VARCHAR(length=64),
               comment='广告主账户id',
               existing_comment='广告账户id',
               existing_nullable=True)
    op.drop_index(op.f('ix_user_oauth_account_account_id'), table_name='user_oauth_account')
    op.create_index(op.f('ix_user_oauth_account_oauth_id'), 'user_oauth_account', ['oauth_id'], unique=False)
    op.drop_column('user_oauth_account', 'account_id')


def downgrade() -> None:
    op.add_column('user_oauth_account', sa.Column('account_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False, comment='授权账户id（user_oauth表中同一个）'))
    op.drop_index(op.f('ix_user_oauth_account_oauth_id'), table_name='user_oauth_account')
    op.create_index(op.f('ix_user_oauth_account_account_id'), 'user_oauth_account', ['account_id'], unique=False)
    op.alter_column('user_oauth_account', 'advertiser_id',
               existing_type=sa.VARCHAR(length=64),
               comment='广告账户id',
               existing_comment='广告主账户id',
               existing_nullable=True)
    op.drop_column('user_oauth_account', 'oauth_id')
    op.drop_column('material_cost', 'report_cnt')
    op.drop_column('material_cost', 'dy_share')
    op.drop_column('material_cost', 'dy_comment')
    op.drop_column('material_cost', 'dy_like')
    op.drop_column('material_cost', 'play_over_rate')
    op.drop_column('material_cost', 'average_play_time_per_play')
    op.drop_column('material_cost', 'valid_play_cost_of_mille')
    op.drop_column('material_cost', 'valid_play_of_mille')
    op.drop_column('material_cost', 'valid_play_rate')
    op.drop_column('material_cost', 'valid_play_cost')
    op.drop_column('material_cost', 'valid_play')
    op.drop_column('material_cost', 'total_play')
    op.drop_column('material_cost', 'in_app_pay_roi')
    op.drop_column('material_cost', 'in_app_pay_gmv')
    op.drop_column('material_cost', 'in_app_order_roi')
    op.drop_column('material_cost', 'in_app_order_gmv')
    op.drop_column('material_cost', 'loan_credit_rate')
    op.drop_column('material_cost', 'loan_credit_cost')
    op.drop_column('material_cost', 'loan_credit')
    op.drop_column('material_cost', 'loan_completion_rate')
    op.drop_column('material_cost', 'loan_completion_cost')
    op.drop_column('material_cost', 'loan_completion')
    op.drop_column('material_cost', 'attribution_game_in_app_roi_1day')
    op.drop_column('material_cost', 'attribution_game_in_app_ltv_1day')
    op.drop_column('material_cost', 'customer_effective')
    op.drop_column('material_cost', 'shopping')
    op.drop_column('material_cost', 'consult_effective')
    op.drop_column('material_cost', 'consult')
    op.drop_column('material_cost', 'message')
    op.drop_column('material_cost', 'view')
    op.drop_column('material_cost', 'button')
    op.drop_column('material_cost', 'form_submit')
    op.drop_column('material_cost', 'download_start')
    op.drop_column('material_cost', 'form')
    op.drop_column('material_cost', 'phone')
    op.drop_column('material_cost', 'active_pay_rate')
    op.drop_column('material_cost', 'active_pay_cost')
    op.drop_column('material_cost', 'active_pay')
    op.drop_column('material_cost', 'attribution_next_day_open_rate')
    op.drop_column('material_cost', 'attribution_next_day_open_cost')
    op.drop_column('material_cost', 'attribution_next_day_open_cnt')