27 lines
1.0 KiB
SQL
27 lines
1.0 KiB
SQL
-- 009: 废弃标题库整合到文案库 (Issue #1894)
|
|
-- 为 scripts 表新增标题相关字段,从 title_libraries 迁移数据
|
|
-- 日期: 2026-09-15
|
|
|
|
-- 1. scripts 表新增字段
|
|
ALTER TABLE scripts ADD COLUMN title_text VARCHAR(500) NOT NULL DEFAULT '';
|
|
ALTER TABLE scripts ADD COLUMN title_category VARCHAR(50) NOT NULL DEFAULT '';
|
|
ALTER TABLE scripts ADD COLUMN title_config JSONB NOT NULL DEFAULT '{}';
|
|
|
|
-- 2. 将 title_libraries 中活跃数据迁移到 scripts 表
|
|
-- 每个用户的每条 title_library 记录,创建一条对应的 script 记录
|
|
INSERT INTO scripts (id, user_id, title, content, segments, tags, title_text, title_category, title_config, created_at, updated_at)
|
|
SELECT
|
|
gen_random_uuid()::TEXT,
|
|
tl.user_id,
|
|
COALESCE(tl.name, '迁移标题'),
|
|
COALESCE(tl.text, ''),
|
|
'[]'::JSONB,
|
|
COALESCE(tl.tags, '[]'::JSONB),
|
|
COALESCE(tl.text, ''),
|
|
COALESCE(tl.category, ''),
|
|
COALESCE(tl.title_config, '{}'::JSONB),
|
|
tl.created_at,
|
|
tl.updated_at
|
|
FROM title_libraries tl
|
|
WHERE tl.is_active = true;
|