把“章节正文 + 图片”从 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>
This commit is contained in:
18
api/migrations/add_section_image_id_fk.sql
Normal file
18
api/migrations/add_section_image_id_fk.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- section 表用 image_id 关联 memoir_images,不再存 JSON
|
||||
-- 执行顺序:1) 本文件 2) 回填后执行 DROP 语句(或由脚本完成)
|
||||
-- 执行方式: psql -U <user> -d <database> -f api/migrations/add_section_image_id_fk.sql
|
||||
|
||||
-- 1. 添加外键列(可空,无默认)
|
||||
ALTER TABLE chapter_sections
|
||||
ADD COLUMN IF NOT EXISTS image_id VARCHAR REFERENCES memoir_images(id) ON DELETE SET NULL;
|
||||
|
||||
-- 2. 回填:已有 memoir_images 且 section_id 指向本行的,把其 id 写入本行 image_id
|
||||
UPDATE chapter_sections cs
|
||||
SET image_id = sub.id
|
||||
FROM (
|
||||
SELECT id, section_id FROM memoir_images WHERE section_id IS NOT NULL
|
||||
) sub
|
||||
WHERE sub.section_id = cs.id AND cs.image_id IS NULL;
|
||||
|
||||
-- 3. 删除旧的 JSON 列
|
||||
ALTER TABLE chapter_sections DROP COLUMN IF EXISTS image;
|
||||
Reference in New Issue
Block a user