Files
photo-live/packages/db-cn/prisma/migrations/20260918102542_stat_replica_columns/migration.sql
T
浅念 955bea49b5 feat(sync): stat snapshot return path with version replacement
P2 Task 9 统计回传(ov→cn):
- cn 迁移:albums 增 viewCountReplica/statsVersion/statsSyncedAt、
  photos 增 statsVersion(like_count 已有副本位;无 VARCHAR 新列不涉校对手决)
- cn 接收端 POST /v1/internal/sync/stat-snapshots(InternalSyncGuard):
  整批单事务,逐快照 updateMany WHERE statsVersion < statVersion —— 仅更高
  statVersion 以权威 total 整体替换副本(绝不相加),重复/乱序幂等忽略;
  accepted 只数实际应用条数;views 应用同时推进 statsSyncedAt(A27 展示)
- ov 回传发送器 services/sync/stat-return.ts:聚合 outbox_stat_events 未发送
  行按(kind, photoId|albumId)取 MAX(statVersion) 折叠突发 → HMAC 推送 →
  200 后按计数器标记截至该版本全部源行 sentAt;失败留待下轮重发;main.ts
  第三循环 STAT_RETURN_INTERVAL_MS(默认 60s,env 可调)
- 契约 AlbumSummary + statsSyncedAt(string|null readOnly,+gen);listAlbums/
  getAlbum 经 toSummaryResponse 暴露(管理 UI 列留 P4a)
- e2e(services/sync stat-return.e2e-spec,7 例):逐次点赞回传替换式收敛
  (2→5→10 非累加)、浏览窗口去重回传 + statsSyncedAt、重复回传 accepted=0
  值不动(A27 不重复累计)、乱序高版本替换(total 可下调)+ 低版本忽略、
  发送端折叠只发最高版本且被折叠行随批确认、管理列表 likeCount/statsSyncedAt
  展示、新端点 401/400 守卫

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-18 18:45:43 +08:00

13 lines
844 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- P2 Task 9:cn 侧统计回传副本列(ov→cn stat-snapshots 接收位)。
-- albums.viewCountReplica/statsVersion/statsSyncedAt:相册浏览数替换式副本 +
-- 回传替换版本(仅更高 statVersion 替换,绝不相加)+ 最近应用时刻(A27 展示
-- 同步时间);photos.statsVersion:likeCount 副本的替换版本比较位
-- (photos.like_count 已存在,P1 起即为副本预留位)。全列带默认值,存量行
-- (副本未同步态 = 0/NULL)与 P1 流程不受影响。无 VARCHAR 新列,不涉校对手决。
ALTER TABLE `albums` ADD COLUMN `statsSyncedAt` DATETIME(6) NULL,
ADD COLUMN `statsVersion` INTEGER NOT NULL DEFAULT 0,
ADD COLUMN `viewCountReplica` INTEGER NOT NULL DEFAULT 0;
-- AlterTable
ALTER TABLE `photos` ADD COLUMN `statsVersion` INTEGER NOT NULL DEFAULT 0;