From 6852609cba12eca729fab6c8dd5b156b2ba20684 Mon Sep 17 00:00:00 2001 From: ogt Date: Wed, 22 Apr 2026 09:25:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E8=A3=9C=E5=BB=BA=20ai=5Finsights?= =?UTF-8?q?=20/=20action=5Fplans=20=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 這兩張表從未存在於生產 DB,導致: - Code Review 每次 _save_to_db() 靜默失敗 - get_history() 永遠返回空陣列 - /code-review/ 頁面歷史永遠空白 已直接在 production DB 執行 CREATE TABLE; 同步更新 docker/postgres/init/01-init.sql, 確保未來重建 DB 時自動建表。 Co-Authored-By: Claude Sonnet 4.6 --- docker/postgres/init/01-init.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docker/postgres/init/01-init.sql b/docker/postgres/init/01-init.sql index b6d5f42..c272cac 100644 --- a/docker/postgres/init/01-init.sql +++ b/docker/postgres/init/01-init.sql @@ -56,6 +56,33 @@ CREATE TABLE IF NOT EXISTS products ( updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); +-- AI Insights — Code Review / Strategy / 洞察結果 +CREATE TABLE IF NOT EXISTS ai_insights ( + id SERIAL PRIMARY KEY, + insight_type VARCHAR(100) NOT NULL, + content TEXT, + confidence FLOAT DEFAULT 0.0, + created_by VARCHAR(100), + status VARCHAR(50) DEFAULT 'active', + metadata_json TEXT, + period VARCHAR(20), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX IF NOT EXISTS idx_ai_insights_type ON ai_insights(insight_type); +CREATE INDEX IF NOT EXISTS idx_ai_insights_created ON ai_insights(created_at DESC); + +-- Action Plans — Code Review 修復 / AIOps 派遣 +CREATE TABLE IF NOT EXISTS action_plans ( + id SERIAL PRIMARY KEY, + action_type VARCHAR(100) NOT NULL, + description TEXT, + status VARCHAR(50) DEFAULT 'pending', + priority INTEGER DEFAULT 3, + metadata_json TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX IF NOT EXISTS idx_action_plans_type ON action_plans(action_type); + -- 授權給 momo 用戶 GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO momo; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO momo;