From 4e2e6652e3d169a0c86373ccc20bc0279cbbcaa1 Mon Sep 17 00:00:00 2001 From: OG T Date: Wed, 15 Apr 2026 16:13:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E7=A7=BB=E9=99=A4=20IncidentEvidenc?= =?UTF-8?q?e.incident=5Fid=20=E7=9A=84=E9=87=8D=E8=A4=87=20index=20?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根本原因:incident_id 同時設定 index=True(mapped_column) 與 __table_args__ 中的 Index("ix_incident_evidence_incident_id"), 導致 table.create 生成重複的 CREATE INDEX, 觸發 "already exists" 被靜默捕捉,整個 CREATE TABLE transaction 回滾。 直接效果:Pod 啟動時 incident_evidence 表永遠不會被建立, 導致後續 ALTER TABLE 失敗 → CrashLoopBackOff。 修法:移除 mapped_column 中的 index=True, 索引由 __table_args__ 統一管理。 注意:已在 PostgreSQL 直接建立 incident_evidence 表解除 CrashLoop。 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/db/models.py b/apps/api/src/db/models.py index a92a606b..3710a736 100644 --- a/apps/api/src/db/models.py +++ b/apps/api/src/db/models.py @@ -759,7 +759,7 @@ class IncidentEvidence(Base): id: Mapped[str] = mapped_column(String(36), primary_key=True, default=generate_uuid) # 關聯 - incident_id: Mapped[str] = mapped_column(String(30), nullable=False, index=True) + incident_id: Mapped[str] = mapped_column(String(30), nullable=False) # index via __table_args__ # Phase 3 填充:matched_playbook_id 目前永久 null,Phase 3 修復 matched_playbook_id: Mapped[str | None] = mapped_column(String(36), nullable=True)