diff --git a/apps/api/src/db/base.py b/apps/api/src/db/base.py index feebc32c..e629b588 100644 --- a/apps/api/src/db/base.py +++ b/apps/api/src/db/base.py @@ -242,6 +242,30 @@ async def init_db() -> None: """) ) + # 2026-04-29 ogt + Claude Opus 4.7: M4 KMWriter 反查鏈 + 冪等補欄 + # CD #1115-1117 全 failure 根因:commit c22e5f33 加 ORM 欄位但無對應 ALTER + # 錯誤:column "related_approval_id" of relation "knowledge_entries" does not exist + # 補防禦性 ALTER(同 timeline_events 模式)+ 對應 index + await conn.execute( + text(""" + ALTER TABLE knowledge_entries + ADD COLUMN IF NOT EXISTS related_approval_id VARCHAR(64), + ADD COLUMN IF NOT EXISTS path_type VARCHAR(50); + """) + ) + # M3 冪等 unique index (incident_id + path_type) + await conn.execute(text( + "CREATE UNIQUE INDEX IF NOT EXISTS uix_knowledge_incident_path " + "ON knowledge_entries(related_incident_id, path_type) " + "WHERE related_incident_id IS NOT NULL AND path_type IS NOT NULL;" + )) + # M4 反查鏈 partial index(approval_id → KM 反查) + await conn.execute(text( + "CREATE INDEX IF NOT EXISTS ix_knowledge_related_approval " + "ON knowledge_entries(related_approval_id) " + "WHERE related_approval_id IS NOT NULL;" + )) + # W2 PR-L1 2026-04-28 ogt + Claude Sonnet 4.6: KM→Playbook 互饋回路(飛輪 C3 修復) # PlaybookRecord 新增 review_required 欄位 # 已存在表不會被 create_all 重建,必須手動 ALTER