-- Phase 29 (ADR-067): PR 自動審查記錄表
-- 2026-04-10 Claude Sonnet 4.6 Asia/Taipei
-- 雙寫: Redis TTL 7d (熱) + PostgreSQL 永久 (冷)

CREATE TABLE IF NOT EXISTS pr_reviews (
    id              SERIAL PRIMARY KEY,
    pr_id           TEXT NOT NULL,           -- Gitea PR number (字串化)
    repo            TEXT NOT NULL,           -- "wooo/awoooi"
    title           TEXT,                    -- PR 標題
    diff_size_bytes INTEGER,                 -- diff 大小 (bytes)
    model           TEXT NOT NULL,           -- qwen2.5-coder:7b / gemini-fallback
    provider        TEXT NOT NULL DEFAULT 'ollama',
    review_text     TEXT NOT NULL,           -- 審查全文
    issues_count    INTEGER DEFAULT 0,       -- 發現問題數
    created_at      TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS ix_pr_reviews_pr_id ON pr_reviews (pr_id);
CREATE INDEX IF NOT EXISTS ix_pr_reviews_created ON pr_reviews (created_at DESC);

COMMENT ON TABLE pr_reviews IS 'PR 自動審查記錄 — Phase 29 ADR-067 (2026-04-10)';
