修改资源素材表字段

This commit is contained in:
18610128193
2026-06-16 09:40:46 +08:00
parent 187eb8f6ff
commit 27aac1a2e6
3 changed files with 379 additions and 0 deletions
@@ -0,0 +1,142 @@
"""修改资源素材表字段
Revision ID: 9216bca75ccf
Revises: acb510c75f6a
Create Date: 2026-06-16 09:39:47.106576
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '9216bca75ccf'
down_revision: Union[str, None] = 'acb510c75f6a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_material_cost_advertiser_id'), 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_deleted_at'), 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_oauth_id'), table_name='material_cost')
op.drop_table('material_cost')
op.drop_index(op.f('ix_resources_material_advertiser_id'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_deleted_at'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_material_id'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_oauth_id'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_resource_type'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_target_id'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_target_table'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_upload_id'), table_name='resources_material')
op.drop_index(op.f('ix_resources_material_user_id'), table_name='resources_material')
op.drop_table('resources_material')
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('resources_material',
sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False, comment='主键'),
sa.Column('oauth_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False, comment='授权表user_oauth自增id'),
sa.Column('advertiser_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='广告主id'),
sa.Column('target_table', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='资源表名称'),
sa.Column('target_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='资源表id'),
sa.Column('material_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='素材id'),
sa.Column('upload_id', sa.VARCHAR(length=128), autoincrement=False, nullable=True, comment='上传资源平台id,图片id,视频id'),
sa.Column('resource_type', sa.VARCHAR(length=16), autoincrement=False, nullable=True, comment='资源类型,image或者video'),
sa.Column('user_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='用户登录id'),
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('resources_material_pkey'))
)
op.create_index(op.f('ix_resources_material_user_id'), 'resources_material', ['user_id'], unique=False)
op.create_index(op.f('ix_resources_material_upload_id'), 'resources_material', ['upload_id'], unique=False)
op.create_index(op.f('ix_resources_material_target_table'), 'resources_material', ['target_table'], unique=False)
op.create_index(op.f('ix_resources_material_target_id'), 'resources_material', ['target_id'], unique=False)
op.create_index(op.f('ix_resources_material_resource_type'), 'resources_material', ['resource_type'], unique=False)
op.create_index(op.f('ix_resources_material_oauth_id'), 'resources_material', ['oauth_id'], unique=False)
op.create_index(op.f('ix_resources_material_material_id'), 'resources_material', ['material_id'], unique=False)
op.create_index(op.f('ix_resources_material_deleted_at'), 'resources_material', ['deleted_at'], unique=False)
op.create_index(op.f('ix_resources_material_advertiser_id'), 'resources_material', ['advertiser_id'], unique=False)
op.create_table('material_cost',
sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False, comment='主键'),
sa.Column('oauth_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False, comment='授权表user_oauth自增id'),
sa.Column('advertiser_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='广告主id'),
sa.Column('material_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True, comment='素材id'),
sa.Column('consume_date', sa.DATE(), autoincrement=False, nullable=False, comment='消耗日期'),
sa.Column('stat_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='消耗金额'),
sa.Column('show_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='展示数'),
sa.Column('cpm_platform', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='平均千次展现费用(元)'),
sa.Column('click_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='点击数'),
sa.Column('ctr', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='点击率'),
sa.Column('cpc_platform', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='平均点击单价(元)'),
sa.Column('convert_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='转化数'),
sa.Column('conversion_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='平均转化成本(元)'),
sa.Column('conversion_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='转化率'),
sa.Column('deep_convert_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='深度转化数'),
sa.Column('deep_convert_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='深度转化成本(元)'),
sa.Column('deep_convert_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='深度转化率'),
sa.Column('active', sa.BIGINT(), autoincrement=False, nullable=True, comment='激活数'),
sa.Column('active_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='激活成本(元)'),
sa.Column('active_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='激活率'),
sa.Column('active_register', sa.BIGINT(), autoincrement=False, nullable=True, comment='注册数'),
sa.Column('active_register_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='注册成本(元)'),
sa.Column('active_register_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='注册率'),
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.Column('attribution_next_day_open_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='次留数'),
sa.Column('attribution_next_day_open_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='次留成本'),
sa.Column('attribution_next_day_open_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='次留率'),
sa.Column('active_pay', sa.BIGINT(), autoincrement=False, nullable=True, comment='首次付费数'),
sa.Column('active_pay_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='首次付费成本(元)'),
sa.Column('active_pay_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='首次付费率'),
sa.Column('phone', sa.BIGINT(), autoincrement=False, nullable=True, comment='点击电话按钮'),
sa.Column('form', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户在门店落地页多线沟通提交表单的次数'),
sa.Column('download_start', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户点击下载开始的次数'),
sa.Column('form_submit', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户查看附加创意后,提交表单的次数'),
sa.Column('button', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户点击按钮button的次数'),
sa.Column('view', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户在关键页面的浏览次数'),
sa.Column('message', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户点击短信咨询的次数'),
sa.Column('consult', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户点击在线咨询按钮的次数'),
sa.Column('consult_effective', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户在门店落地页多线沟通的在线咨询中有效咨询的次数'),
sa.Column('shopping', sa.BIGINT(), autoincrement=False, nullable=True, comment='用户购买商品的次数'),
sa.Column('customer_effective', sa.BIGINT(), autoincrement=False, nullable=True, comment='有效获客'),
sa.Column('attribution_game_in_app_ltv_1day', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='当日付费金额'),
sa.Column('attribution_game_in_app_roi_1day', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='当日付费ROI'),
sa.Column('loan_completion', sa.BIGINT(), autoincrement=False, nullable=True, comment='完件数互联网金融-贷款行业中,用户成功提交贷款额度申请的行为'),
sa.Column('loan_completion_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='完件成本(元)'),
sa.Column('loan_completion_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='完件率'),
sa.Column('loan_credit', sa.BIGINT(), autoincrement=False, nullable=True, comment='互联网金融-贷款行业中,用户提交贷款额度申请后,客户审批通过,给予用户可贷款的额度'),
sa.Column('loan_credit_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='授信成本(元)'),
sa.Column('loan_credit_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='授信率'),
sa.Column('in_app_order_gmv', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='当您使用"in_app_order"事件回传订单金额时,对应的GMV金额,引流电商订单GMV'),
sa.Column('in_app_order_roi', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='引流电商订单ROI'),
sa.Column('in_app_pay_gmv', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='引流电商支付GMV'),
sa.Column('in_app_pay_roi', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='引流电商支付ROI'),
sa.Column('total_play', sa.BIGINT(), autoincrement=False, nullable=True, comment='播放量播放时间大于0S的数量,在某些蜂窝网络环境下,需要您手动点击开始才会开始播放,因此有时播放数小于展示数。'),
sa.Column('valid_play', sa.BIGINT(), autoincrement=False, nullable=True, comment='有效播放数'),
sa.Column('valid_play_cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='有效播放成本(元)'),
sa.Column('valid_play_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='有效播放率'),
sa.Column('valid_play_of_mille', sa.BIGINT(), autoincrement=False, nullable=True, comment='千次有效播放数'),
sa.Column('valid_play_cost_of_mille', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='千次有效播放成本(元)'),
sa.Column('average_play_time_per_play', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='平均单次播放时长'),
sa.Column('play_over_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True, comment='完播率'),
sa.Column('dy_like', sa.BIGINT(), autoincrement=False, nullable=True, comment='点赞数'),
sa.Column('dy_comment', sa.BIGINT(), autoincrement=False, nullable=True, comment='评论量'),
sa.Column('dy_share', sa.BIGINT(), autoincrement=False, nullable=True, comment='分享量'),
sa.Column('report_cnt', sa.BIGINT(), autoincrement=False, nullable=True, comment='举报数'),
sa.PrimaryKeyConstraint('id', name=op.f('material_cost_pkey'))
)
op.create_index(op.f('ix_material_cost_oauth_id'), 'material_cost', ['oauth_id'], 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_deleted_at'), 'material_cost', ['deleted_at'], 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_advertiser_id'), 'material_cost', ['advertiser_id'], unique=False)
# ### end Alembic commands ###
+201
View File
@@ -0,0 +1,201 @@
from sqlalchemy import BigInteger, Date, Float, String
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base, TimestampMixin, SoftDeleteMixin
class MaterialCost(Base, TimestampMixin, SoftDeleteMixin):
__tablename__ = "material_cost"
id: Mapped[str] = mapped_column(
String(32), primary_key=True, comment="主键"
)
oauth_id: Mapped[str] = mapped_column(
String(64), nullable=False, index=True, comment="授权表user_oauth自增id"
)
advertiser_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, index=True, comment="广告主id"
)
material_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, index=True, comment="素材id"
)
consume_date: Mapped[Date] = mapped_column(
Date, nullable=False, index=True, comment="消耗日期"
)
stat_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="消耗金额"
)
show_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="展示数"
)
cpm_platform: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="平均千次展现费用(元)"
)
click_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="点击数"
)
ctr: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="点击率"
)
cpc_platform: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="平均点击单价(元)"
)
convert_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="转化数"
)
conversion_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="平均转化成本(元)"
)
conversion_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="转化率"
)
deep_convert_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="深度转化数"
)
deep_convert_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="深度转化成本(元)"
)
deep_convert_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="深度转化率"
)
active: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="激活数"
)
active_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="激活成本(元)"
)
active_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="激活率"
)
active_register: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="注册数"
)
active_register_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="注册成本(元)"
)
active_register_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="注册率"
)
attribution_next_day_open_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="次留数"
)
attribution_next_day_open_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="次留成本"
)
attribution_next_day_open_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="次留率"
)
active_pay: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="首次付费数"
)
active_pay_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="首次付费成本(元)"
)
active_pay_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="首次付费率"
)
phone: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="点击电话按钮"
)
form: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户在门店落地页多线沟通提交表单的次数"
)
download_start: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户点击下载开始的次数"
)
form_submit: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户查看附加创意后,提交表单的次数"
)
button: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户点击按钮button的次数"
)
view: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户在关键页面的浏览次数"
)
message: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户点击短信咨询的次数"
)
consult: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户点击在线咨询按钮的次数"
)
consult_effective: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户在门店落地页多线沟通的在线咨询中有效咨询的次数"
)
shopping: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="用户购买商品的次数"
)
customer_effective: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="有效获客"
)
attribution_game_in_app_ltv_1day: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="当日付费金额"
)
attribution_game_in_app_roi_1day: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="当日付费ROI"
)
loan_completion: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="完件数互联网金融-贷款行业中,用户成功提交贷款额度申请的行为"
)
loan_completion_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="完件成本(元)"
)
loan_completion_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="完件率"
)
loan_credit: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="互联网金融-贷款行业中,用户提交贷款额度申请后,客户审批通过,给予用户可贷款的额度"
)
loan_credit_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="授信成本(元)"
)
loan_credit_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="授信率"
)
in_app_order_gmv: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="当您使用\"in_app_order\"事件回传订单金额时,对应的GMV金额,引流电商订单GMV"
)
in_app_order_roi: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="引流电商订单ROI"
)
in_app_pay_gmv: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="引流电商支付GMV"
)
in_app_pay_roi: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="引流电商支付ROI"
)
total_play: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="播放量播放时间大于0S的数量,在某些蜂窝网络环境下,需要您手动点击开始才会开始播放,因此有时播放数小于展示数。"
)
valid_play: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="有效播放数"
)
valid_play_cost: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="有效播放成本(元)"
)
valid_play_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="有效播放率"
)
valid_play_of_mille: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="千次有效播放数"
)
valid_play_cost_of_mille: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="千次有效播放成本(元)"
)
average_play_time_per_play: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="平均单次播放时长"
)
play_over_rate: Mapped[float | None] = mapped_column(
Float, nullable=True, comment="完播率"
)
dy_like: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="点赞数"
)
dy_comment: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="评论量"
)
dy_share: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="分享量"
)
report_cnt: Mapped[int | None] = mapped_column(
BigInteger, nullable=True, comment="举报数"
)
@@ -0,0 +1,36 @@
from sqlalchemy import BigInteger, String
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base, TimestampMixin, SoftDeleteMixin
class ResourcesMaterial(Base, TimestampMixin, SoftDeleteMixin):
__tablename__ = "resources_material"
id: Mapped[str] = mapped_column(
String(32), primary_key=True, comment="主键"
)
oauth_id: Mapped[str] = mapped_column(
String(64), nullable=False, index=True, comment="授权表user_oauth自增id"
)
advertiser_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, index=True, comment="广告主id"
)
target_table: Mapped[str | None] = mapped_column(
String(64), nullable=True, comment="资源表名称"
)
target_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, comment="资源表id"
)
material_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, index=True, comment="素材id"
)
upload_id: Mapped[str | None] = mapped_column(
String(128), nullable=True, comment="上传资源平台id,图片id,视频id"
)
resource_type: Mapped[str | None] = mapped_column(
String(16), nullable=True, comment="资源类型,image或者video"
)
user_id: Mapped[str | None] = mapped_column(
String(64), nullable=True, index=True, comment="用户登录id"
)