Spaces:
Runtime error
Runtime error
File size: 830 Bytes
e0e1fd3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | -- Create the Chat History Table
CREATE TABLE IF NOT EXISTS public.chat_history (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
query TEXT NOT NULL,
answer TEXT NOT NULL,
sources JSONB DEFAULT '[]'::jsonb,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- Turn on Row Level Security (RLS)
ALTER TABLE public.chat_history ENABLE ROW LEVEL SECURITY;
-- Allow users to insert their own chats
CREATE POLICY "Users can insert their own chat history"
ON public.chat_history FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id);
-- Allow users to view their own chats
CREATE POLICY "Users can view their own chat history"
ON public.chat_history FOR SELECT
TO authenticated
USING (auth.uid() = user_id);
|