feat(auto-repair): 所有操作強制寫入 DB — auto_repair_executions 表
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 1m32s
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 1m32s
統帥指令: 所有自動修復操作(成功/失敗)必須持久化 變更: - migrations/phase10_auto_repair_executions.sql: 新增表 + 4 個索引 - db/models.py: 新增 AutoRepairExecution SQLAlchemy model - repositories/audit_log_repository.py: 新增 AutoRepairExecutionRepository (create/list_by_incident/get_stats) - auto_repair_service.py: execute_auto_repair 成功/失敗分支都寫入 DB - 新增 similarity_score 參數傳遞 - AutoRepairDecision 新增 similarity_score 欄位 - webhooks.py: 傳入 similarity_score 到 execute_auto_repair 已執行 migration: awoooi_prod@192.168.0.188:5432 ✅ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -352,6 +352,50 @@ class AuditLog(Base):
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# AutoRepairExecution - Phase 10 操作記錄
|
||||
# 2026-04-08 Claude Code: 統帥指令「所有操作都必須被記錄,寫入資料庫」
|
||||
# =============================================================================
|
||||
|
||||
class AutoRepairExecution(Base):
|
||||
"""
|
||||
自動修復執行記錄
|
||||
|
||||
每次 evaluate_auto_repair 觸發並執行 (成功或失敗) 都寫入此表。
|
||||
不依賴 approval_id(自動修復不需人工批准)。
|
||||
"""
|
||||
__tablename__ = "auto_repair_executions"
|
||||
|
||||
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)
|
||||
playbook_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
||||
playbook_name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
|
||||
# 執行結果
|
||||
success: Mapped[bool] = mapped_column(default=False, nullable=False)
|
||||
executed_steps: Mapped[list] = mapped_column(JSON, default=list, nullable=False)
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
# 執行上下文
|
||||
triggered_by: Mapped[str] = mapped_column(
|
||||
String(50), default="auto_repair", nullable=False,
|
||||
comment="auto_repair / cold_start_trust",
|
||||
)
|
||||
similarity_score: Mapped[float | None] = mapped_column(nullable=True)
|
||||
risk_level: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
||||
execution_time_ms: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
|
||||
# 時間戳 (台北時區)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=taipei_now)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_are_created_at", "created_at"),
|
||||
Index("ix_are_success", "success"),
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# IncidentRecord - Phase 6.2 Episodic Memory (PostgreSQL)
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user