Files
awoooi/apps/api/migrations/phase7_playbooks_table.sql
OG T df3ef9006c
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 7m2s
fix(auto-repair): 首席架構師 Review — 4 Critical/Important 修復
Critical #1: KM write task 移出 try/except
- _trigger_learning 的 KM 寫入原在 try 內,learning 失敗時不寫 KM
- 移至 except 後確保成功/失敗都寫入
- 移除冗餘 import asyncio(已在頂層 import)
- Minor: approval.incident_id or None 防空字串

Important #2: migration 加 PRIMARY KEY
- playbook_id 從 UNIQUE 升為 PRIMARY KEY
- prod DB 已執行 ALTER TABLE ADD PRIMARY KEY

Important #3: s.sequence→s.step_number, s.description→s.command
- embed_playbook() 使用不存在的欄位名,RAG 向量索引靜默失敗
- RepairStep 正確欄位: step_number, command

Important #1: PlaybookService._get_rag_service 不再 Service 層快取
- 改為每次呼叫工廠 get_playbook_rag_service()
- 避免舊實例繞過工廠的 is_closed 重建邏輯

冷啟動修復 (首席架構師建議B+C):
- _trigger_playbook_extraction 執行成功後自動設定
  execution_success=True, effectiveness_score=4, status=RESOLVED
- skip 路徑 logger.debug → logger.info 提升可觀測性

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 12:02:03 +08:00

60 lines
2.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Phase 7: Playbook 萃取功能 — playbooks 資料表
-- 建立時間: 2026-04-04 (台北時區)
-- 建立者: Claude Code (Phase 7 補齊 migration)
-- 對應設計: memory/project_playbook_design.md
-- 對應模型: apps/api/src/models/playbook.py
CREATE TABLE IF NOT EXISTS playbooks (
-- 識別
-- 2026-04-04 ogt: 首席架構師 Review — 加 PRIMARY KEY移除多餘 UNIQUE
playbook_id VARCHAR(32) PRIMARY KEY,
-- 元資料
name VARCHAR(256) NOT NULL,
description TEXT NOT NULL DEFAULT '',
status VARCHAR(32) NOT NULL DEFAULT 'draft', -- draft|approved|deprecated
source VARCHAR(32) NOT NULL DEFAULT 'extracted', -- extracted|manual
-- 症狀模式 (SymptomPattern JSON)
symptom_pattern JSONB NOT NULL DEFAULT '{}',
-- 修復步驟 (list[RepairStep] JSON)
repair_steps JSONB NOT NULL DEFAULT '[]',
estimated_duration_minutes INT NOT NULL DEFAULT 5,
-- 來源追溯
source_incident_ids TEXT[] NOT NULL DEFAULT '{}',
ai_confidence DECIMAL(4,3) NOT NULL DEFAULT 0.0,
-- 統計數據
success_count INT NOT NULL DEFAULT 0,
failure_count INT NOT NULL DEFAULT 0,
last_used_at TIMESTAMPTZ,
-- 人工標記
approved_by VARCHAR(128),
approved_at TIMESTAMPTZ,
tags TEXT[] NOT NULL DEFAULT '{}',
notes TEXT,
-- 時間軸
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- 索引
CREATE INDEX IF NOT EXISTS idx_playbooks_status
ON playbooks(status);
CREATE INDEX IF NOT EXISTS idx_playbooks_tags
ON playbooks USING GIN(tags);
CREATE INDEX IF NOT EXISTS idx_playbooks_alert_names
ON playbooks USING GIN((symptom_pattern->'alert_names'));
CREATE INDEX IF NOT EXISTS idx_playbooks_source_incidents
ON playbooks USING GIN(source_incident_ids);
CREATE INDEX IF NOT EXISTS idx_playbooks_created_at
ON playbooks(created_at DESC);