Spaces:
Configuration error
Configuration error
Download database/02_rls.sql from rockysreenivasa/MathTutor: direct link, hf CLI and curl.
- Browser
- Download file 3.76 kB
-
https://huggingface.co/spaces/rockysreenivasa/MathTutor/resolve/main/database/02_rls.sql
- Command line
-
hf download hf://spaces/rockysreenivasa/MathTutor/database/02_rls.sql
-
curl -L -o 02_rls.sql https://huggingface.co/spaces/rockysreenivasa/MathTutor/resolve/main/database/02_rls.sql
3.76 kB
| -- ============================================================ | |
| -- MathMind AI β Row Level Security (RLS) | |
| -- Run AFTER 01_schema.sql | |
| -- ============================================================ | |
| -- Enable RLS on all student-data tables | |
| alter table public.profiles enable row level security; | |
| alter table public.sessions enable row level security; | |
| alter table public.practice_attempts enable row level security; | |
| alter table public.test_results enable row level security; | |
| alter table public.student_badges enable row level security; | |
| -- badges table is read-only for all authenticated users (definitions, not student data) | |
| alter table public.badges enable row level security; | |
| -- ββ profiles βββββββββββββββββββββββββββββββββββββββββββββββ | |
| create policy "Students can view own profile" | |
| on public.profiles for select | |
| using (auth.uid() = id); | |
| create policy "Students can update own profile" | |
| on public.profiles for update | |
| using (auth.uid() = id); | |
| create policy "Students can insert own profile" | |
| on public.profiles for insert | |
| with check (auth.uid() = id); | |
| -- ββ sessions βββββββββββββββββββββββββββββββββββββββββββββββ | |
| create policy "Students can view own sessions" | |
| on public.sessions for select | |
| using (auth.uid() = user_id); | |
| create policy "Students can insert own sessions" | |
| on public.sessions for insert | |
| with check (auth.uid() = user_id); | |
| -- ββ practice_attempts ββββββββββββββββββββββββββββββββββββββ | |
| -- Students access their own attempts via session ownership | |
| create policy "Students can view own practice attempts" | |
| on public.practice_attempts for select | |
| using ( | |
| exists ( | |
| select 1 from public.sessions s | |
| where s.id = practice_attempts.session_id | |
| and s.user_id = auth.uid() | |
| ) | |
| ); | |
| create policy "Students can insert own practice attempts" | |
| on public.practice_attempts for insert | |
| with check ( | |
| exists ( | |
| select 1 from public.sessions s | |
| where s.id = practice_attempts.session_id | |
| and s.user_id = auth.uid() | |
| ) | |
| ); | |
| -- ββ test_results βββββββββββββββββββββββββββββββββββββββββββ | |
| create policy "Students can view own test results" | |
| on public.test_results for select | |
| using (auth.uid() = user_id); | |
| create policy "Students can insert own test results" | |
| on public.test_results for insert | |
| with check (auth.uid() = user_id); | |
| -- ββ badges (definitions β read-only for all auth users) ββββ | |
| create policy "All authenticated users can read badges" | |
| on public.badges for select | |
| using (auth.role() = 'authenticated'); | |
| -- ββ student_badges βββββββββββββββββββββββββββββββββββββββββ | |
| create policy "Students can view own earned badges" | |
| on public.student_badges for select | |
| using (auth.uid() = user_id); | |
| create policy "Students can insert own earned badges" | |
| on public.student_badges for insert | |
| with check (auth.uid() = user_id); | |
| -- ββ Service role bypass ββββββββββββββββββββββββββββββββββββ | |
| -- The FastAPI backend uses service_role key which bypasses RLS. | |
| -- This is intentional β backend does server-side validation before | |
| -- writing to the DB. Never expose service_role key to the client. | |