feat(compare): comparison_record 加 best_deeplink 列 + 迁移(再次比价直达商家深链备用)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""comparison_record 加 best_deeplink(再次比价直达商家深链)
|
||||
|
||||
Revision ID: b7e2c1a9f4d3
|
||||
Revises: 9258bddde4ea
|
||||
Create Date: 2026-06-05
|
||||
|
||||
「再次比价」要直达上次最低价平台的商家/商品页。深链(link)在比价时客户端已从剪贴板采到
|
||||
(collectedLinks[best_index]),本列把它落库;再次比价时写剪贴板 + launch 该平台 App 直达。
|
||||
旧记录无此列值(None) → 前端降级为打开对应 App 首页。
|
||||
|
||||
手写迁移(只加一列):autogenerate 会误报"删 order_record"(降级为审计的历史表,model 已移除、
|
||||
库表保留),手写规避该噪音。
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "b7e2c1a9f4d3"
|
||||
down_revision: Union[str, Sequence[str], None] = "9258bddde4ea"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table("comparison_record", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("best_deeplink", sa.String(length=1024), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("comparison_record", schema=None) as batch_op:
|
||||
batch_op.drop_column("best_deeplink")
|
||||
@@ -64,6 +64,9 @@ class ComparisonRecord(Base):
|
||||
best_platform_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
best_platform_name: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
best_price_cents: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
# 最优平台的商家/商品深链(客户端比价时从剪贴板采到 = collectedLinks[best_index]);
|
||||
# 「再次比价」写剪贴板 + launch 该平台 App 直达。仅 2026-06 起新比价有,旧记录为 None。
|
||||
best_deeplink: Mapped[str | None] = mapped_column(String(1024), nullable=True)
|
||||
# 源价 - 最优价(可为 0 / 负:源平台本来就最便宜时没省到)
|
||||
saved_amount_cents: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
# 源平台就是最便宜的一家(= 这次没省到钱)
|
||||
|
||||
@@ -79,6 +79,7 @@ def upsert_record(
|
||||
source_platform_name=payload.source_platform_name,
|
||||
source_package=payload.source_package,
|
||||
information=payload.information,
|
||||
best_deeplink=payload.best_deeplink,
|
||||
total_dish_count=payload.total_dish_count,
|
||||
skipped_dish_count=payload.skipped_dish_count,
|
||||
items=[it.model_dump(exclude_none=True) for it in payload.items],
|
||||
|
||||
@@ -62,6 +62,8 @@ class ComparisonRecordIn(BaseModel):
|
||||
information: str | None = Field(None, description="done 帧文案,留存备查")
|
||||
# 不传则服务端按 comparison_results 派生(有非源有效价=success,否则 failed)
|
||||
status: str | None = Field(None, description="success / failed,可不传由服务端派生")
|
||||
# 最优平台商家/商品深链(客户端从 collectedLinks[best_index] 取);「再次比价」直达用
|
||||
best_deeplink: str | None = Field(None, description="最优平台深链,再次比价直达")
|
||||
|
||||
|
||||
# ===== 读取出参 =====
|
||||
@@ -81,6 +83,7 @@ class ComparisonRecordOut(BaseModel):
|
||||
best_platform_id: str | None = None
|
||||
best_platform_name: str | None = None
|
||||
best_price_cents: int | None = None
|
||||
best_deeplink: str | None = None
|
||||
saved_amount_cents: int | None = None
|
||||
is_source_best: bool | None = None
|
||||
store_name: str | None = None
|
||||
|
||||
Reference in New Issue
Block a user