Files
FruitServer/sql/migrate-k109-legacy-drama-like-cleanup.sql
T
Vicky 884324b8fd chore(sql): 清理历史遗留的剧级点赞数据
客户端点赞入口只作用于剧集,13 条 DRAMA 记录为旧模型遗留;
软删并同步校准 drama.like_count。
2026-10-27 13:28:15 +08:00

24 lines
818 B
PL/PgSQL
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.
-- Author: fruit.com.cn
-- K109 清理历史遗留的「按整部剧点赞」数据。
-- 产品口径:收藏按剧,点赞与评论按集。客户端点赞入口只作用于当前剧集
-- (targetType = EPISODE),以下 DRAMA 记录均为 2026-10-21 15:49 之前的旧模型遗留。
BEGIN;
UPDATE content_like
SET deleted = 1
WHERE target_type = 'DRAMA' AND deleted = 0;
-- 剧级点赞数由这些行累加而来,随软删一并按实际剩余行数校准,避免详情页展示虚高数字。
UPDATE drama d
SET like_count = sub.cnt
FROM (
SELECT d2.id, COUNT(l.id) AS cnt
FROM drama d2
LEFT JOIN content_like l
ON l.target_type = 'DRAMA' AND l.target_id = d2.id AND l.deleted = 0
GROUP BY d2.id
) sub
WHERE d.id = sub.id AND d.like_count IS DISTINCT FROM sub.cnt;
COMMIT;