Spaces:
Sleeping
Sleeping
Download supabase_schema.sql from Abdullah0327/Docent-AI-ChatBot: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/Abdullah0327/Docent-AI-ChatBot/resolve/main/supabase_schema.sql
- Command line
-
hf download hf://spaces/Abdullah0327/Docent-AI-ChatBot/supabase_schema.sql
-
curl -L -o supabase_schema.sql https://huggingface.co/spaces/Abdullah0327/Docent-AI-ChatBot/resolve/main/supabase_schema.sql
2.73 kB
| -- ============================================================================ | |
| -- Docent AI β Supabase schema for authentication-backed chat history | |
| -- Run this ONCE in your Supabase project: | |
| -- Dashboard β SQL Editor β New query β paste this file β Run | |
| -- ============================================================================ | |
| -- ββ Conversations (one row per chat) βββββββββββββββββββββββββββββββββββββββ | |
| create table if not exists public.chat_sessions ( | |
| id uuid primary key default gen_random_uuid(), | |
| user_id uuid not null references auth.users (id) on delete cascade, | |
| title text not null default 'New chat', | |
| created_at timestamptz not null default now(), | |
| updated_at timestamptz not null default now() | |
| ); | |
| -- ββ Messages (user + assistant turns) ββββββββββββββββββββββββββββββββββββββ | |
| create table if not exists public.messages ( | |
| id uuid primary key default gen_random_uuid(), | |
| session_id uuid not null references public.chat_sessions (id) on delete cascade, | |
| role text not null check (role in ('user', 'assistant')), | |
| content text not null, | |
| sources jsonb not null default '[]'::jsonb, | |
| created_at timestamptz not null default now() | |
| ); | |
| -- User feedback on assistant answers: 'up', 'down', or null | |
| alter table public.messages add column if not exists feedback text; | |
| create index if not exists idx_sessions_user on public.chat_sessions (user_id, updated_at desc); | |
| create index if not exists idx_messages_session on public.messages (session_id, created_at); | |
| -- ββ Row Level Security ββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| -- The backend uses the service-role key (which bypasses RLS), but we still | |
| -- enable RLS so the public anon key can never read another user's data. | |
| alter table public.chat_sessions enable row level security; | |
| alter table public.messages enable row level security; | |
| drop policy if exists "own sessions" on public.chat_sessions; | |
| create policy "own sessions" on public.chat_sessions | |
| for all | |
| using (auth.uid() = user_id) | |
| with check (auth.uid() = user_id); | |
| drop policy if exists "own messages" on public.messages; | |
| create policy "own messages" on public.messages | |
| for all | |
| using (exists ( | |
| select 1 from public.chat_sessions s | |
| where s.id = messages.session_id and s.user_id = auth.uid() | |
| )) | |
| with check (exists ( | |
| select 1 from public.chat_sessions s | |
| where s.id = messages.session_id and s.user_id = auth.uid() | |
| )); | |