update
This commit is contained in:
@ -18,7 +18,11 @@ ALTER TABLE street_snaps
|
||||
ADD COLUMN IF NOT EXISTS status varchar(16) NOT NULL DEFAULT 'pending',
|
||||
ADD COLUMN IF NOT EXISTS job_id bigint NOT NULL DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS reviewer varchar(64) NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS reject_reason varchar(255) NOT NULL DEFAULT '';
|
||||
ADD COLUMN IF NOT EXISTS reject_reason varchar(255) NOT NULL DEFAULT '',
|
||||
-- 街拍标题中文化:保留既有 title 作英文源,仅加 title_cn 供后台人工翻译、前端按 locale 取用。
|
||||
-- 与 brand_runways 用 title_en/title_cn 不同:street_snaps 上有 uq_ss_entity(city, year, COALESCE(title,'')),
|
||||
-- 改名成本过高;pickLocale 在中文为空时回落英文,无需数据回灌。
|
||||
ADD COLUMN IF NOT EXISTS title_cn text NOT NULL DEFAULT '';
|
||||
|
||||
-- 2) 存量行置已发布**不在本文件里**:它是数据变更且只能执行一次,见同目录
|
||||
-- 2026-09-22-01b-publish-existing-rows.sql。
|
||||
@ -31,14 +35,20 @@ CREATE INDEX IF NOT EXISTS idx_br_status ON brand_runways (status);
|
||||
CREATE INDEX IF NOT EXISTS idx_ss_status ON street_snaps (status);
|
||||
|
||||
-- 4) 公开只读视图:把「必须是已发布且未删除」固化成结构性保证,公开查询漏写过滤成为不可能。
|
||||
-- 注意:视图列集被 SELECT * 冻结 —— 以后给这 4 张基表加列,必须同批重建视图。
|
||||
-- 视图列集显式枚举(非 SELECT *):只暴露对外需要的列,刻意排除审核/溯源列
|
||||
-- (job_id / reviewer / reject_reason),避免敏感列随基表加列被无意暴露到公开读路径。
|
||||
-- 图片子视图仍取 i.*(图片表无敏感列);改动基表列集时按本文件同批重建视图。
|
||||
DROP VIEW IF EXISTS public_brand_runway_images;
|
||||
DROP VIEW IF EXISTS public_brand_runways;
|
||||
DROP VIEW IF EXISTS public_street_snap_images;
|
||||
DROP VIEW IF EXISTS public_street_snaps;
|
||||
|
||||
CREATE VIEW public_brand_runways AS
|
||||
SELECT * FROM brand_runways WHERE status = 'published' AND is_deleted = 0;
|
||||
SELECT
|
||||
id, brand_id, title_en, title_cn, description_en, description_cn,
|
||||
cover, image_count, year, collection_type, season, season_code,
|
||||
status, is_deleted, created_at, updated_at
|
||||
FROM brand_runways WHERE status = 'published' AND is_deleted = 0;
|
||||
|
||||
CREATE VIEW public_brand_runway_images AS
|
||||
SELECT i.* FROM brand_runway_images i
|
||||
@ -46,7 +56,10 @@ CREATE VIEW public_brand_runway_images AS
|
||||
WHERE i.is_deleted = 0 AND r.status = 'published' AND r.is_deleted = 0;
|
||||
|
||||
CREATE VIEW public_street_snaps AS
|
||||
SELECT * FROM street_snaps WHERE status = 'published' AND is_deleted = 0;
|
||||
SELECT
|
||||
id, title, title_cn, year, city, cover, image_count,
|
||||
status, is_deleted, created_at, updated_at
|
||||
FROM street_snaps WHERE status = 'published' AND is_deleted = 0;
|
||||
|
||||
CREATE VIEW public_street_snap_images AS
|
||||
SELECT i.* FROM street_snap_images i
|
||||
|
||||
37
db/migrations/2026-09-24-01-runway-parent-image-id.sql
Normal file
37
db/migrations/2026-09-24-01-runway-parent-image-id.sql
Normal file
@ -0,0 +1,37 @@
|
||||
-- 2026-09-24-01 走秀图片改用 parent_image_id 分组(与街拍同构),移除 look_index。
|
||||
--
|
||||
-- 背景:走秀图片原用 look_index 把「主图 + 细节图」归到同一 Look 桶(look_index 仅作为分组桶号,
|
||||
-- 对产品无意义)。现统一为 parent_image_id(细节图直接指向所属主图的行 id),与 street_snap_images
|
||||
-- 完全同构,后台可复用同一套「合并 / 拆出」逻辑。
|
||||
--
|
||||
-- 步骤:
|
||||
-- 1) 给 brand_runway_images 加 parent_image_id 列(与街拍对齐,默认 0);
|
||||
-- 2) 回填:每个 look 内 is_detail=0 的主图,其同 look 的 is_detail=1 细节图 parent_image_id 置为该主图 id;
|
||||
-- 3) 删 look_index 列;
|
||||
-- 4) 重建 public_brand_runway_images 视图(原 SELECT i.* 在删列后失效,重建即按新列集展开)。
|
||||
--
|
||||
-- 幂等:ADD COLUMN IF NOT EXISTS;视图 DROP VIEW IF EXISTS 后重建。
|
||||
-- 应用后请重新导出结构:dbtool dump -clean -out db_dump.sql
|
||||
|
||||
ALTER TABLE brand_runway_images ADD COLUMN IF NOT EXISTS parent_image_id bigint NOT NULL DEFAULT 0;
|
||||
|
||||
-- 回填:对每个 runway,把每个 look 的 is_detail=1 细节图 parent_image_id 置为该 look 内 is_detail=0 主图的 id。
|
||||
-- 孤儿细节图(同 look 无主图)保持 parent_image_id=0(COALESCE 兜底,避免 NOT NULL 报错)。
|
||||
UPDATE brand_runway_images AS d
|
||||
SET parent_image_id = COALESCE((
|
||||
SELECT MIN(m.id)
|
||||
FROM brand_runway_images AS m
|
||||
WHERE m.runway_id = d.runway_id
|
||||
AND m.look_index = d.look_index
|
||||
AND m.is_detail = 0
|
||||
AND m.is_deleted = 0
|
||||
), 0)
|
||||
WHERE d.is_detail = 1 AND d.is_deleted = 0 AND d.parent_image_id = 0;
|
||||
|
||||
ALTER TABLE brand_runway_images DROP COLUMN IF EXISTS look_index;
|
||||
|
||||
DROP VIEW IF EXISTS public_brand_runway_images;
|
||||
CREATE VIEW public_brand_runway_images AS
|
||||
SELECT i.* FROM brand_runway_images i
|
||||
JOIN brand_runways r ON r.id = i.runway_id
|
||||
WHERE i.is_deleted = 0 AND r.status = 'published' AND r.is_deleted = 0;
|
||||
Reference in New Issue
Block a user