Files
xiaoxia-saas/migrations/009_merge_title_library_into_scripts.sql
T
灵应 7cea7a938c
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m0s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m43s
AI Code Review / AI Code Review (pull_request) Successful in 6m23s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 7m28s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 7m28s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m43s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m45s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 3m10s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 4m19s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 21h50m5s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 21h57m34s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 21h49m24s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 21h56m52s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 21h56m53s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 21h56m53s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 21h56m54s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 21h56m54s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 21h56m54s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 21h56m55s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 21h49m24s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 21h56m50s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 21h56m50s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 22h32m29s
fix(#1894): add alembic migration 077 for title fields auto-deploy
编程Agent 只写了根目录 migrations/009.sql(手动执行),但没有 alembic 迁移文件,
staging/生产部署时 Watchtower 不会自动执行根目录 SQL,导致 title_text/title_category/title_config
三个列缺失、脚本报错。补 alembic 077 迁移确保部署时自动建列+数据迁移。

同时给 migrations/009.sql 加上 IF NOT EXISTS 保护和幂等 INSERT 防止重复执行报错。
2026-09-15 17:24:29 +08:00

34 lines
1.4 KiB
SQL

-- 009: 废弃标题库整合到文案库 (Issue #1894)
-- 为 scripts 表新增标题相关字段,从 title_libraries 迁移数据
-- 日期: 2026-09-15
-- 注意:此文件为手动执行 SQL,正式部署通过 alembic 版本 077 自动迁移(含 IF NOT EXISTS 幂等保护)
-- 1. scripts 表新增字段
ALTER TABLE scripts ADD COLUMN IF NOT EXISTS title_text VARCHAR(500) NOT NULL DEFAULT '';
ALTER TABLE scripts ADD COLUMN IF NOT EXISTS title_category VARCHAR(50) NOT NULL DEFAULT '';
ALTER TABLE scripts ADD COLUMN IF NOT EXISTS title_config JSONB NOT NULL DEFAULT '{}';
-- 2. 将 title_libraries 中活跃数据迁移到 scripts 表(幂等:已迁移过的跳过)
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
AND NOT EXISTS (
SELECT 1 FROM scripts s
WHERE s.user_id = tl.user_id
AND s.title_text = COALESCE(tl.text, '')
AND s.title_category = COALESCE(tl.category, '')
AND s.created_at = tl.created_at
);