feat(catalog): 新增分类推荐榜快照接口
backend-ci / test (push) Failing after 4m45s

This commit is contained in:
Zhou Weidong committed 2026-11-02 14:45:43 +08:00
1 parent afd8d00752
commit 8a5a381b44
23 files changed
+793 -16

No files matched your search

@@ -0,0 +1,50 @@
-- Author: fruit.com.cn
-- 推荐榜:运营分类增加稳定语义、展示类型和版本,关联关系增加明确位置
ALTER TABLE drama_classification
ADD COLUMN IF NOT EXISTS code VARCHAR(64),
ADD COLUMN IF NOT EXISTS layout_type VARCHAR(16) NOT NULL DEFAULT 'GRID',
ADD COLUMN IF NOT EXISTS revision BIGINT NOT NULL DEFAULT 1;
UPDATE drama_classification
SET code = 'CLASSIFICATION_' || id
WHERE code IS NULL OR BTRIM(code) = '';
UPDATE drama_classification
SET code = 'RECOMMEND_RANKING',
layout_type = 'RANKING'
WHERE id = (
SELECT id
FROM drama_classification
WHERE name IN ('推荐榜', '榜单')
ORDER BY sort ASC, id ASC
LIMIT 1
);
CREATE UNIQUE INDEX IF NOT EXISTS uk_drama_classification_code
ON drama_classification (code);
ALTER TABLE drama_classification_drama
ADD COLUMN IF NOT EXISTS position INTEGER NOT NULL DEFAULT 0;
WITH ranked AS (
SELECT id,
ROW_NUMBER() OVER (
PARTITION BY classification_id
ORDER BY created_at DESC, id DESC
) AS next_position
FROM drama_classification_drama
)
UPDATE drama_classification_drama relation
SET position = ranked.next_position
FROM ranked
WHERE relation.id = ranked.id
AND relation.position = 0;
CREATE INDEX IF NOT EXISTS idx_classification_drama_position
ON drama_classification_drama (classification_id, position, id);
COMMENT ON COLUMN drama_classification.code IS '稳定语义码,不随多语言名称变化';
COMMENT ON COLUMN drama_classification.layout_type IS '客户端布局:GRID/RANKING';
COMMENT ON COLUMN drama_classification.revision IS '内容或顺序版本,变更后递增';
COMMENT ON COLUMN drama_classification_drama.position IS '分类内展示位置,从 1 开始';
+13 -6
View File
@@ -873,26 +873,33 @@ COMMENT ON TABLE audit_log IS '业务对象变更审计(支付、权益、定
-- ============================================================
CREATE TABLE IF NOT EXISTS drama_classification (
id BIGINT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
sort INTEGER NOT NULL DEFAULT 0,
status SMALLINT NOT NULL DEFAULT 1,
created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
id BIGINT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
code VARCHAR(64),
layout_type VARCHAR(16) NOT NULL DEFAULT 'GRID',
revision BIGINT NOT NULL DEFAULT 1,
sort INTEGER NOT NULL DEFAULT 0,
status SMALLINT NOT NULL DEFAULT 1,
created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS uk_drama_classification_name ON drama_classification (name);
CREATE UNIQUE INDEX IF NOT EXISTS uk_drama_classification_code ON drama_classification (code);
COMMENT ON TABLE drama_classification IS '运营分类;与短剧类型(drama_category)相互独立';
CREATE TABLE IF NOT EXISTS drama_classification_drama (
id BIGINT PRIMARY KEY,
classification_id BIGINT NOT NULL,
drama_id BIGINT NOT NULL,
position INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS uk_classification_drama
ON drama_classification_drama (classification_id, drama_id);
CREATE INDEX IF NOT EXISTS idx_classification_drama_drama
ON drama_classification_drama (drama_id);
CREATE INDEX IF NOT EXISTS idx_classification_drama_position
ON drama_classification_drama (classification_id, position, id);
COMMENT ON TABLE drama_classification_drama IS '分类与短剧的关联关系';
-- ============================================================