Files
life-echo/api/migrations/add_chapter_sections.sql
Sully 2eb066dbec 把“章节正文 + 图片”从 chapters 单表/JSON 结构,重构为“章节 chapter + 段落 section + 图片 memoir_images 独立表”的新数据模型,同时联动修改接口、PDF 导出、异步任务、迁移脚本、测试,以及修复 Android 端聊天列表显示问题。 (#9)
* refactor: 表结构重构,新增段落section和图片image新表

* fix: fix android app import error

* refactor: 重构文件名

* fix: 优化提示词

* fix: 消息气泡显示位置异常问题

---------

Co-authored-by: yangshilin <2157598560@qq.com>
2026-03-13 11:12:10 +08:00

27 lines
1.2 KiB
SQL
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.
-- 章节拆分为 chapter_sections每段正文 + 配图独立存储chapters 只保留封面图
-- 执行顺序: 1) 本文件 2) python -m scripts.migrate_chapters_to_sections
-- 执行方式: psql -U <user> -d <database> -f api/migrations/add_chapter_sections.sql
-- ========== 1. 新建 chapter_sections 表 ==========
CREATE TABLE IF NOT EXISTS chapter_sections (
id VARCHAR NOT NULL PRIMARY KEY,
chapter_id VARCHAR NOT NULL REFERENCES chapters(id) ON DELETE CASCADE,
order_index INTEGER NOT NULL,
content TEXT NOT NULL,
image JSONB,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS ix_chapter_sections_chapter_id ON chapter_sections(chapter_id);
CREATE INDEX IF NOT EXISTS ix_chapter_sections_order ON chapter_sections(chapter_id, order_index);
-- ========== 2. chapters 表增加 cover_image ==========
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'chapters' AND column_name = 'cover_image') THEN
ALTER TABLE chapters ADD COLUMN cover_image JSONB;
RAISE NOTICE '已添加 chapters.cover_image';
END IF;
END $$;
-- ========== 3. 回填与删列由脚本 scripts.migrate_chapters_to_sections 完成 ==========