-- 093_ai_conversation_summary.sql
-- Auto-generated summaries of AI conversations for memory context

CREATE TABLE IF NOT EXISTS ai_conversation_summary (
    id SERIAL PRIMARY KEY,
    conversation_id INTEGER NOT NULL UNIQUE REFERENCES ai_chat_conversations(id) ON DELETE CASCADE,
    user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    summary TEXT NOT NULL,
    key_topics JSONB DEFAULT '[]',
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX idx_ai_conv_summary_user ON ai_conversation_summary(user_id, created_at DESC);

GRANT ALL ON TABLE ai_conversation_summary TO nordabiz_app;
GRANT USAGE, SELECT ON SEQUENCE ai_conversation_summary_id_seq TO nordabiz_app;
