fcfac7ad07
- 新表 price_report:关联比价记录,存原最低价快照(反查 best_*)/上报平台+价/截图URL/审核状态(pending/approved/rejected)/奖励字段 - POST /api/v1/report (multipart):反查比价记录填原最低价,校验上报价 < 原最低价(D),截图复用 core.media 落 /media/price_report/,提交一律 pending - GET /api/v1/report/records?status= :按状态筛选 + 四态 counts,供「上报记录」页 - core.media 加 save_report_image;main 挂 report 路由;models 登记 PriceReport - alembic 迁移仅建 price_report(autogenerate 误检的「删 order_record」已手动剔除——那是降级为审计的历史表) 奖励发放(通过→钱包+1000金币)是人工审核后台动作,本期不含。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
66 lines
3.2 KiB
Python
66 lines
3.2 KiB
Python
"""新增 price_report 上报更低价表
|
|
|
|
Revision ID: 9258bddde4ea
|
|
Revises: ad60a1b2c3d4
|
|
Create Date: 2026-06-05 10:15:51.508598
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '9258bddde4ea'
|
|
down_revision: Union[str, Sequence[str], None] = 'ad60a1b2c3d4'
|
|
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.create_table('price_report',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('comparison_record_id', sa.Integer(), nullable=True),
|
|
sa.Column('store_name', sa.String(length=128), nullable=True),
|
|
sa.Column('dish_summary', sa.String(length=256), nullable=True),
|
|
sa.Column('original_platform_id', sa.String(length=32), nullable=True),
|
|
sa.Column('original_platform_name', sa.String(length=32), nullable=True),
|
|
sa.Column('original_price_cents', sa.Integer(), nullable=True),
|
|
sa.Column('reported_platform_id', sa.String(length=32), nullable=False),
|
|
sa.Column('reported_platform_name', sa.String(length=32), nullable=False),
|
|
sa.Column('reported_price_cents', sa.Integer(), nullable=False),
|
|
sa.Column('images', sa.JSON(), nullable=False),
|
|
sa.Column('status', sa.String(length=16), nullable=False),
|
|
sa.Column('reject_reason', sa.String(length=256), nullable=True),
|
|
sa.Column('reward_coins', sa.Integer(), nullable=True),
|
|
sa.Column('reviewed_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.ForeignKeyConstraint(['comparison_record_id'], ['comparison_record.id'], ),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('price_report', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_price_report_comparison_record_id'), ['comparison_record_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_price_report_created_at'), ['created_at'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_price_report_status'), ['status'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_price_report_user_id'), ['user_id'], unique=False)
|
|
# 注:autogenerate 另检测到「删除 order_record 表」——那是已降级为审计的历史表
|
|
# (model 已移除、库表保留),与本次无关,手动剔除,避免误删他人审计数据。
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
# (对称:upgrade 未删 order_record,downgrade 也不重建它)
|
|
with op.batch_alter_table('price_report', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_price_report_user_id'))
|
|
batch_op.drop_index(batch_op.f('ix_price_report_status'))
|
|
batch_op.drop_index(batch_op.f('ix_price_report_created_at'))
|
|
batch_op.drop_index(batch_op.f('ix_price_report_comparison_record_id'))
|
|
|
|
op.drop_table('price_report')
|
|
# ### end Alembic commands ###
|