nxtgauge-backend-rust/crates/db/migrations/20260608010000_ai_feedback.up.sql
2026-06-08 06:15:58 +05:30

23 lines
859 B
PL/PgSQL

-- AI Feedback: thumbs-up/down on Ask Ash replies, plus optional free-form comment.
-- Used by /api/ai/feedback endpoint. Backed by ai_conversations (ON DELETE SET NULL
-- so feedback survives even if the source conversation is purged).
BEGIN;
CREATE TABLE IF NOT EXISTS ai_feedback (
id BIGSERIAL PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
conversation_id UUID REFERENCES ai_conversations(id) ON DELETE SET NULL,
helpful BOOLEAN NOT NULL,
comment TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_ai_feedback_user
ON ai_feedback (user_id, created_at DESC);
-- Hot path: "was this conversation helpful?" analytics
CREATE INDEX IF NOT EXISTS idx_ai_feedback_conversation
ON ai_feedback (conversation_id);
COMMIT;