Create supabase_data.txt
Browse files- supabase_data.txt +70 -0
supabase_data.txt
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# === Database Schema (Example - Create these tables in your Supabase project) ===
|
| 2 |
+
"""
|
| 3 |
+
-- users table (Supabase Auth handles this mostly, but you might add custom fields)
|
| 4 |
+
CREATE TABLE IF NOT EXISTS public.profiles (
|
| 5 |
+
id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
|
| 6 |
+
email VARCHAR(255) UNIQUE,
|
| 7 |
+
credits INTEGER DEFAULT 30, -- Example credit system
|
| 8 |
+
is_admin BOOLEAN DEFAULT FALSE,
|
| 9 |
+
created_at TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL,
|
| 10 |
+
suspended BOOLEAN DEFAULT FALSE
|
| 11 |
+
-- Add other profile fields as needed
|
| 12 |
+
);
|
| 13 |
+
-- Function to automatically create a profile when a new user signs up in Auth
|
| 14 |
+
create function public.handle_new_user()
|
| 15 |
+
returns trigger
|
| 16 |
+
language plpgsql
|
| 17 |
+
security definer set search_path = public
|
| 18 |
+
as $$
|
| 19 |
+
begin
|
| 20 |
+
insert into public.profiles (id, email)
|
| 21 |
+
values (new.id, new.email);
|
| 22 |
+
return new;
|
| 23 |
+
end;
|
| 24 |
+
$$;
|
| 25 |
+
-- Trigger to call the function after a user is inserted into auth.users
|
| 26 |
+
create trigger on_auth_user_created
|
| 27 |
+
after insert on auth.users
|
| 28 |
+
for each row execute procedure public.handle_new_user();
|
| 29 |
+
|
| 30 |
+
-- study_materials table
|
| 31 |
+
CREATE TABLE IF NOT EXISTS public.study_materials (
|
| 32 |
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
| 33 |
+
user_id UUID REFERENCES public.profiles(id) ON DELETE CASCADE NOT NULL,
|
| 34 |
+
type VARCHAR(50) NOT NULL, -- 'pdf', 'youtube', 'wiki', 'bible', 'arxiv', 'text'
|
| 35 |
+
source_ref TEXT NOT NULL, -- URL, Bible reference, ArXiv ID, filename, or part of the text prompt
|
| 36 |
+
source_content TEXT, -- Store extracted text here (optional, can be large)
|
| 37 |
+
created_at TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL,
|
| 38 |
+
title TEXT -- Optional: Title extracted or generated
|
| 39 |
+
);
|
| 40 |
+
|
| 41 |
+
-- notes table
|
| 42 |
+
CREATE TABLE IF NOT EXISTS public.notes (
|
| 43 |
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
| 44 |
+
material_id UUID REFERENCES public.study_materials(id) ON DELETE CASCADE NOT NULL,
|
| 45 |
+
user_id UUID REFERENCES public.profiles(id) ON DELETE CASCADE NOT NULL,
|
| 46 |
+
content TEXT NOT NULL, -- The generated notes
|
| 47 |
+
created_at TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL,
|
| 48 |
+
tts_audio_url TEXT -- URL to the TTS audio file in Supabase Storage
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
-- quizzes table
|
| 52 |
+
CREATE TABLE IF NOT EXISTS public.quizzes (
|
| 53 |
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
| 54 |
+
notes_id UUID REFERENCES public.notes(id) ON DELETE CASCADE NOT NULL,
|
| 55 |
+
user_id UUID REFERENCES public.profiles(id) ON DELETE CASCADE NOT NULL,
|
| 56 |
+
difficulty VARCHAR(10) NOT NULL, -- 'easy', 'medium', 'hard'
|
| 57 |
+
questions JSONB NOT NULL, -- Store the list of question objects {question: "", options: {A:"", B:"", C:"", D:""}, correct_answer: "A"}
|
| 58 |
+
created_at TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
-- quiz_attempts table
|
| 62 |
+
CREATE TABLE IF NOT EXISTS public.quiz_attempts (
|
| 63 |
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
| 64 |
+
quiz_id UUID REFERENCES public.quizzes(id) ON DELETE CASCADE NOT NULL,
|
| 65 |
+
user_id UUID REFERENCES public.profiles(id) ON DELETE CASCADE NOT NULL,
|
| 66 |
+
score NUMERIC(5, 2) NOT NULL, -- e.g., 85.00 for 85%
|
| 67 |
+
answers JSONB NOT NULL, -- Store the user's answers {question_index: "selected_option"}
|
| 68 |
+
submitted_at TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL
|
| 69 |
+
);
|
| 70 |
+
"""
|