-- Migration: Create document_feedback table
-- Created: 2024-01-01

CREATE TABLE IF NOT EXISTS document_feedback (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    document_id UUID NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    feedback TEXT NOT NULL,
    regeneration_instructions TEXT,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- Create indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_document_feedback_document_id ON document_feedback(document_id);
CREATE INDEX IF NOT EXISTS idx_document_feedback_user_id ON document_feedback(user_id);
CREATE INDEX IF NOT EXISTS idx_document_feedback_created_at ON document_feedback(created_at);

-- Create composite index for document feedback with user
CREATE INDEX IF NOT EXISTS idx_document_feedback_document_user ON document_feedback(document_id, user_id); 