-- Phase 25 P2: Config Drift Detection — drift_reports 資料表 -- 建立時間: 2026-04-04 (台北時區) -- 建立者: Claude Code (Phase 25 P2) -- 對應模型: apps/api/src/models/drift.py -- 對應設計: docs/superpowers/specs/2026-04-04-nemotron-active-defense-design.md 方向三 -- -- 執行方式: psql -h 192.168.0.188 -U awoooi -d awoooi -f phase9_drift_reports.sql CREATE TABLE IF NOT EXISTS drift_reports ( -- 識別 report_id VARCHAR(32) PRIMARY KEY, -- 掃描資訊 namespace VARCHAR(128) NOT NULL, triggered_by VARCHAR(64) NOT NULL DEFAULT 'cron', -- cron / webhook / api scanned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- 計數(非正規化,避免每次 JOIN) high_count INT NOT NULL DEFAULT 0, medium_count INT NOT NULL DEFAULT 0, info_count INT NOT NULL DEFAULT 0, -- 漂移項目(JSONB 列表) items JSONB NOT NULL DEFAULT '[]', -- Nemotron 意圖分析 interpretation JSONB, -- DriftInterpretation,可為 NULL(尚未分析) -- 處理狀態 status VARCHAR(32) NOT NULL DEFAULT 'pending', -- pending / acknowledged / rolled_back / adopted / ignored -- 時間軸 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), resolved_at TIMESTAMPTZ ); -- 索引 CREATE INDEX IF NOT EXISTS idx_drift_reports_namespace ON drift_reports(namespace); CREATE INDEX IF NOT EXISTS idx_drift_reports_status ON drift_reports(status); CREATE INDEX IF NOT EXISTS idx_drift_reports_created_at ON drift_reports(created_at DESC); CREATE INDEX IF NOT EXISTS idx_drift_reports_high_count ON drift_reports(high_count) WHERE high_count > 0; -- 說明: -- 目前 API 使用 in-memory dict 暫存,此表供未來持久化使用 -- 啟用持久化後,需在 drift.py 的 _recent_reports 操作改為 DB 寫入