-- Phase 10: Auto Repair Executions 操作記錄表 -- 建立時間: 2026-04-08 (台北時區) -- 建立者: Claude Code — 統帥指令「所有操作都必須被記錄,寫入資料庫」 -- -- 設計說明: -- 自動修復每次執行(成功或失敗)都寫入此表 -- 不依賴 approval_id(自動修復不需要人工批准) -- 支援查詢: 按 incident / playbook / 時間範圍 / 成功率 CREATE TABLE IF NOT EXISTS auto_repair_executions ( -- 主鍵 id VARCHAR(36) PRIMARY KEY DEFAULT gen_random_uuid()::text, -- 關聯 incident_id VARCHAR(30) NOT NULL, playbook_id VARCHAR(36) NOT NULL, playbook_name VARCHAR(200) NOT NULL, -- 執行結果 success BOOLEAN NOT NULL DEFAULT FALSE, executed_steps JSONB NOT NULL DEFAULT '[]', -- list of step result strings error_message TEXT, -- 執行上下文 triggered_by VARCHAR(50) NOT NULL DEFAULT 'auto_repair', -- auto_repair / cold_start_trust similarity_score NUMERIC(5,4), -- 匹配相似度 risk_level VARCHAR(20), -- LOW / MEDIUM / HIGH execution_time_ms INTEGER, -- 時間戳 (台北時區) created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- 索引 CREATE INDEX IF NOT EXISTS ix_are_incident_id ON auto_repair_executions (incident_id); CREATE INDEX IF NOT EXISTS ix_are_playbook_id ON auto_repair_executions (playbook_id); CREATE INDEX IF NOT EXISTS ix_are_created_at ON auto_repair_executions (created_at DESC); CREATE INDEX IF NOT EXISTS ix_are_success ON auto_repair_executions (success);