-- ADR-007：AI_insights DB 實體表建立
-- 日期: 2026-04-18

CREATE TABLE IF NOT EXISTS ai_insights (
    id SERIAL PRIMARY KEY,
    insight_type VARCHAR(50) NOT NULL,
    period VARCHAR(50),
    product_sku VARCHAR(50),
    content TEXT NOT NULL,
    metadata_json TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_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_period ON ai_insights(period);
CREATE INDEX IF NOT EXISTS idx_ai_insights_sku ON ai_insights(product_sku);
CREATE INDEX IF NOT EXISTS idx_ai_insights_created ON ai_insights(created_at);

-- 注意：Step 3 才會在此表加上 embedding vector(1024) 欄位
