TrinetraLabs/Placebo_AI
0
1-- Create the Chat History Table2CREATE TABLE IF NOT EXISTS public.chat_history (3 id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,4 user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,5 query TEXT NOT NULL,6 answer TEXT NOT NULL,7 sources JSONB DEFAULT '[]'::jsonb,8 created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL9);10 11-- Turn on Row Level Security (RLS)12ALTER TABLE public.chat_history ENABLE ROW LEVEL SECURITY;13 14-- Allow users to insert their own chats15CREATE POLICY "Users can insert their own chat history"16ON public.chat_history FOR INSERT17TO authenticated18WITH CHECK (auth.uid() = user_id);19 20-- Allow users to view their own chats21CREATE POLICY "Users can view their own chat history"22ON public.chat_history FOR SELECT23TO authenticated24USING (auth.uid() = user_id);25 