重构回忆录为 story-first / markdown-first 架构并整合图片意图与前端 UI 修复
本次 squash merge 将 codex-story-first-image-intent 的整体改动合入 development,核心内容包括: 1. 后端数据与迁移:新增 stories、story_versions、story_image_intents、chapter_cover_intents、assets 等模型与 Alembic 迁移,建立 story-first、markdown-first、asset-first 的主数据链路。 2. 生成与任务链:引入 StoryBuilderOrchestrator、ChapterComposerOrchestrator、story_image_tasks、chapter_cover_tasks,图片生成从正文占位符改为结构化 intent -> asset -> markdown 回填。 3. 并发与一致性:为 story/chapter intent 增加 claim_token、claimed_at、attempt_count,采用数据库原子 claim 为主、Redis 锁为辅,避免重复生成、锁误删和 processing 卡死。 4. Memoir 读写路径:章节 canonical_markdown 成为正文真源,列表/详情接口补齐 markdown、cover_asset、word_count 等字段,PDF 与 asset 解析链路同步升级。 5. Memory / Retrieval:扩展 transcript ingest、chunking、evidence 检索与 story 聚合基础设施,为后续 story-first RAG 与多 agent 编排提供底座。 6. App 端体验:章节页继续走 MarkdownRenderer 阅读链,同时吸收 fix3-19 的跨平台 UI glitch 修复;更新对话页、首页、文案资源与章节列表映射逻辑。 7. 测试与文档:补充 asset resolver、story image task、章节封面派发、markdown 映射等回归测试,并加入图片占位符退役设计文档。
This commit is contained in:
72
api/alembic/versions/0009_story_image_intent_constraints.py
Normal file
72
api/alembic/versions/0009_story_image_intent_constraints.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""story_image_intents: one primary per story + optional FK to assets
|
||||
|
||||
Revision ID: 0009_si_constraints
|
||||
Revises: 0008_legacy_assets
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0009_si_constraints"
|
||||
down_revision: Union[str, Sequence[str], None] = "0008_legacy_assets"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE story_image_intents SET asset_id = NULL
|
||||
WHERE asset_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM assets a WHERE a.id = story_image_intents.asset_id)
|
||||
"""
|
||||
)
|
||||
)
|
||||
# 去重:同一 story 多条 primary 时保留最新一条
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM story_image_intents
|
||||
WHERE id IN (
|
||||
SELECT id FROM (
|
||||
SELECT id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY story_id
|
||||
ORDER BY created_at DESC NULLS LAST, id DESC
|
||||
) AS rn
|
||||
FROM story_image_intents
|
||||
WHERE intent_role = 'primary'
|
||||
) t
|
||||
WHERE rn > 1
|
||||
)
|
||||
"""
|
||||
)
|
||||
)
|
||||
op.create_foreign_key(
|
||||
"fk_story_image_intents_asset_id_assets",
|
||||
"story_image_intents",
|
||||
"assets",
|
||||
["asset_id"],
|
||||
["id"],
|
||||
ondelete="SET NULL",
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_story_primary_image_intent
|
||||
ON story_image_intents (story_id)
|
||||
WHERE intent_role = 'primary'
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute("DROP INDEX IF EXISTS uq_story_primary_image_intent")
|
||||
op.drop_constraint(
|
||||
"fk_story_image_intents_asset_id_assets",
|
||||
"story_image_intents",
|
||||
type_="foreignkey",
|
||||
)
|
||||
Reference in New Issue
Block a user