Spaces:
Running
Running
Download db/001_schema.sql from lilyjeongwon/math-tutor: direct link, hf CLI and curl.
- Browser
- Download file 20.4 kB
-
https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/db/001_schema.sql
- Command line
-
hf download hf://spaces/lilyjeongwon/math-tutor/db/001_schema.sql
-
curl -L -o 001_schema.sql https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/db/001_schema.sql
20.4 kB
| -- ===================================================================== | |
| -- k12-math-rag-tutor : 001_schema.sql | |
| -- Supabase(PostgreSQL 15+) SQL Editor ์์ ํต์งธ๋ก ์คํํฉ๋๋ค. (์ฌ๋ฌ ๋ฒ ์คํํด๋ ์์ ) | |
| -- ์์: 001_schema.sql -> 002_seed_units.sql | |
| -- | |
| -- ๋ณด์ ์์น | |
| -- * ํ์ ๋ธ๋ผ์ฐ์ /ํจ๋๋ Supabase ์ ์ง์ ์ ์ํ์ง ์์ต๋๋ค. | |
| -- Gradio ์๋ฒ(HF Space)๋ง service_role ํค๋ก ์ ์ํฉ๋๋ค. (ํค๋ HF Secrets ์๋ง ๋ณด๊ด) | |
| -- * ๊ทธ๋๋ ๋ง์ผ์ ๋๋นํด ๋ชจ๋ ํ ์ด๋ธ์ RLS ๋ฅผ ์ผ๊ณ , ์ ๋ต/ํด์ค์ด ๋ | |
| -- questions ๋ service_role ์ธ์๋ ์ฝ์ ์ ์๊ฒ ๋ก๋๋ค. | |
| -- ===================================================================== | |
| -- --------------------------------------------------------------------- | |
| -- 0. ๊ณตํต: enum, updated_at ํธ๋ฆฌ๊ฑฐ | |
| -- --------------------------------------------------------------------- | |
| do $$ begin | |
| create type user_role as enum ('student', 'teacher', 'admin'); | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type question_type as enum ('multiple_choice', 'short_answer'); | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type difficulty as enum ('low', 'mid', 'high'); -- ํ / ์ค / ์ | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type question_status as enum ('draft', 'review', 'published', 'retired'); | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type rights_status as enum ('unreviewed', 'cleared', 'restricted'); -- ์ด์ฉ ํ๋ฝ ํ์ธ ์ํ | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type session_status as enum ('in_progress', 'completed', 'abandoned'); | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type step_phase as enum ('ladder', 'retry'); -- ํโ์คโ์ ์ฌ๋ค๋ฆฌ / ์ค๋ต ์ฌ๋์ | |
| exception when duplicate_object then null; end $$; | |
| do $$ begin | |
| create type step_outcome as enum ('pending', 'correct', 'wrong'); | |
| exception when duplicate_object then null; end $$; | |
| create or replace function set_updated_at() | |
| returns trigger language plpgsql as $$ | |
| begin | |
| new.updated_at = now(); | |
| return new; | |
| end $$; | |
| -- --------------------------------------------------------------------- | |
| -- 1. ๊ต์ก๊ณผ์ ๋ง์คํฐ (์์ญ 5๊ฐ / ๋จ์ 77๊ฐ = ๊ณ ๋ฑ 42 + ์คํ๊ต ๋ณต์ต 35) | |
| -- '์์ด๊ณผ ์กฐํฉ'์ ๊ณตํต์ํ๊ณผ ํ๋ฅ ๊ณผ ํต๊ณ ์์ชฝ์ ๋ณด์ด์ง๋ง ๋จ์์ 1๊ฐ์ ๋๋ค. | |
| -- -> units(๋จ์ 1๊ฐ) + unit_areas(์์ญ ์์, ๋ค๋๋ค) | |
| -- --------------------------------------------------------------------- | |
| create table if not exists areas ( | |
| area_id text primary key, -- common | math1 | math2 | stats | middle | |
| name_ko text not null unique, | |
| sort_order smallint not null | |
| ); | |
| create table if not exists units ( | |
| unit_id text primary key, -- U01~U42(๊ณ ๋ฑ), M01~M35(์คํ๊ต). ๋ฐ๋์ง ์๋ ์๋ณ์ | |
| name_ko text not null unique, | |
| keywords text[] not null default '{}',-- 04_tag_curriculum_meta.py ํค์๋ (1์ฐจ ํ๊น ์ฉ) | |
| sort_order smallint not null | |
| ); | |
| -- ํ๊ต๊ธ๊ณผ ์๋ฒ ์ด์ ๋ฒ์ (์ด๋ฏธ ๋ง๋ DB ์๋ ์์ ํ๊ฒ ์ถ๊ฐ๋ฉ๋๋ค) | |
| alter table units add column if not exists level text not null default 'high'; | |
| alter table units add column if not exists pilot boolean not null default false; | |
| do $$ begin | |
| if not exists (select 1 from pg_constraint where conname = 'units_level_check') then | |
| alter table units add constraint units_level_check check (level in ('high', 'middle')); | |
| end if; | |
| end $$; | |
| create table if not exists unit_areas ( | |
| unit_id text not null references units(unit_id) on delete cascade, | |
| area_id text not null references areas(area_id) on delete cascade, | |
| sort_order smallint not null, -- ์์ญ ์์์์ ํ์ ์์ | |
| primary key (unit_id, area_id) | |
| ); | |
| create table if not exists unit_prerequisites ( | |
| unit_id text not null references units(unit_id) on delete cascade, | |
| prerequisite_id text not null references units(unit_id) on delete cascade, | |
| primary key (unit_id, prerequisite_id), | |
| check (unit_id <> prerequisite_id) | |
| ); | |
| -- --------------------------------------------------------------------- | |
| -- 2. ์ฌ์ฉ์ / ํ๊ธ | |
| -- --------------------------------------------------------------------- | |
| create table if not exists profiles ( | |
| id uuid primary key references auth.users(id) on delete cascade, | |
| email text, | |
| name text, | |
| role user_role not null default 'student', -- ์ญํ ๋ณ๊ฒฝ์ ๊ด๋ฆฌ์(service_role)๋ง | |
| created_at timestamptz not null default now(), | |
| updated_at timestamptz not null default now() | |
| ); | |
| drop trigger if exists trg_profiles_updated on profiles; | |
| create trigger trg_profiles_updated before update on profiles | |
| for each row execute function set_updated_at(); | |
| -- ๊ตฌ๊ธ ๋ก๊ทธ์ธ์ผ๋ก auth.users ๊ฐ ์๊ธฐ๋ฉด profiles ํ์ ์๋ ์์ฑ (๊ธฐ๋ณธ ์ญํ : student) | |
| create or replace function handle_new_user() | |
| returns trigger language plpgsql security definer set search_path = public as $$ | |
| begin | |
| insert into public.profiles (id, email, name) | |
| values ( | |
| new.id, | |
| new.email, | |
| coalesce(new.raw_user_meta_data ->> 'full_name', new.raw_user_meta_data ->> 'name') | |
| ) | |
| on conflict (id) do nothing; | |
| return new; | |
| end $$; | |
| drop trigger if exists on_auth_user_created on auth.users; | |
| create trigger on_auth_user_created after insert on auth.users | |
| for each row execute function handle_new_user(); | |
| create table if not exists classes ( | |
| id uuid primary key default gen_random_uuid(), | |
| school_year smallint not null, -- ์: 2027 | |
| grade smallint not null check (grade between 1 and 3), | |
| class_no smallint not null check (class_no >= 1), | |
| homeroom_teacher_id uuid references profiles(id) on delete set null, | |
| created_at timestamptz not null default now(), | |
| unique (school_year, grade, class_no) | |
| ); | |
| create table if not exists class_members ( | |
| class_id uuid not null references classes(id) on delete cascade, | |
| student_id uuid not null references profiles(id) on delete cascade, | |
| student_no smallint, -- ๋ฒํธ | |
| primary key (class_id, student_id) | |
| ); | |
| create index if not exists idx_class_members_student on class_members(student_id); | |
| -- --------------------------------------------------------------------- | |
| -- 3. ๋ฌธ์ ์ํ | |
| -- ETL(05 ๊ฒ์ฆ, 06 ์ ์ฌ)์ ํต๊ณผํ ๋ฌธํญ๋ง published ๊ฐ ๋ ์ ์์ต๋๋ค. | |
| -- --------------------------------------------------------------------- | |
| create table if not exists questions ( | |
| id uuid primary key default gen_random_uuid(), | |
| -- ์ถ์ฒ ์ถ์ (์ฌ์ ์ฌ/์ค๋ณต ๋ฐฉ์ง) | |
| source text not null check (source in ('aihub', 'ebsi', 'jsj50', 'teacher', 'other')), | |
| source_ref text not null, -- ์๋ณธ ๋ฌธํญ ์๋ณ์ (์: 2026_10_hs1_q07) | |
| source_meta jsonb not null default '{}'::jsonb,-- ์๋ณธ ๋ฉํ(ai_hub_meta ๋ฑ) | |
| rights_status rights_status not null default 'unreviewed', | |
| -- ๋ถ๋ฅ | |
| grade_code text not null check (grade_code in ('e3','e4','e5','e6','m1','m2','m3','h1','h2','h3')), | |
| unit_id text references units(unit_id), -- ํ๊น ์ ์๋ null | |
| difficulty difficulty, -- ํ๊น ์ ์๋ null | |
| score smallint, -- EBSi ๋ฐฐ์ (๋์ด๋ ์์ ๊ธฐ์ค) | |
| -- ๋ณธ๋ฌธ (์์์ LaTeX ๋ฅผ $...$ ๋ก ๊ฐ์ธ ์ ์ฅ) | |
| qtype question_type not null, | |
| stem_md text not null, | |
| choices jsonb not null default '[]'::jsonb,-- ["โ ...", "โก..."] ๊ฐ๊ด์๋ง | |
| figure_description text, -- VLM ๋ํ ๋ฌ์ฌ | |
| figure_path text, -- Supabase Storage ๊ฒฝ๋ก | |
| -- ์ ๋ต/ํด์ค (ํ์์๊ฒ ์ง์ ๋ ธ์ถ ๊ธ์ง) | |
| answer text not null, -- ๊ฐ๊ด์: '1'~'5', ์ฃผ๊ด์: ์ ๋ต ๋ฌธ์์ด | |
| accepted_answers text[] not null default '{}', -- ๋์น ํ๊ธฐ ํ์ฉ ๋ชฉ๋ก | |
| solution_md text, | |
| intent text, -- ์ถ์ ์๋ | |
| -- ํ์ง ๊ด๋ฆฌ | |
| verified boolean not null default false, -- 05 ๊ฒ์ฆ(์ ๋ตํยทํด์คยท์ฌ๊ณ์ฐ) ํต๊ณผ ์ฌ๋ถ | |
| verify_note text, | |
| status question_status not null default 'draft', | |
| created_at timestamptz not null default now(), | |
| updated_at timestamptz not null default now(), | |
| unique (source, source_ref), | |
| -- ๊ฐ๊ด์์ ์ ํ์ง๊ฐ ์์ด์ผ ํจ | |
| check (qtype <> 'multiple_choice' or jsonb_array_length(choices) >= 2), | |
| -- ๊ฒ์(published) ์กฐ๊ฑด: ๋จ์ยท๋์ด๋ ํ๊น + ๊ฒ์ฆ + ์ด์ฉ ํ๋ฝ ํ์ธ | |
| -- (ํ์ผ๋ฟ์์ ์ํํ๋ ค๋ฉด rights_status ์กฐ๊ฑด๋ง ์กฐ์ ํ์ธ์) | |
| check ( | |
| status <> 'published' | |
| or (unit_id is not null and difficulty is not null | |
| and verified and rights_status = 'cleared' | |
| and solution_md is not null) | |
| ) | |
| ); | |
| drop trigger if exists trg_questions_updated on questions; | |
| create trigger trg_questions_updated before update on questions | |
| for each row execute function set_updated_at(); | |
| -- ๋ฌธ์ ๋ฝ๊ธฐ์ฉ: ๋จ์ x ๋์ด๋ x ๊ฒ์ ์ํ | |
| create index if not exists idx_questions_pick | |
| on questions (unit_id, difficulty) where status = 'published'; | |
| create index if not exists idx_questions_grade on questions (grade_code); | |
| -- ํ์ ์ค๋ฅ ์ ๊ณ | |
| create table if not exists question_reports ( | |
| id uuid primary key default gen_random_uuid(), | |
| question_id uuid not null references questions(id) on delete cascade, | |
| reporter_id uuid references profiles(id) on delete set null, | |
| reason text not null, | |
| resolved boolean not null default false, | |
| created_at timestamptz not null default now() | |
| ); | |
| create index if not exists idx_reports_open on question_reports (resolved, created_at); | |
| -- --------------------------------------------------------------------- | |
| -- 4. ํ์ต ์ธ์ / ์ถ์ ๋ชฉ๋ก / ์๋ | |
| -- study_sessions : ํ์์ด ์ด๋ ๋ ์ด๋ ๋จ์์ ๊ณจ๋๋์ง (ํ๋ฃจ 1์ธ์ /๋จ์) | |
| -- session_questions: ๊ทธ ์ธ์ ์์ ๋ธ ๋ฌธ์ ์์ (์ฌ๋ค๋ฆฌ + ์ค๋ต ์ฌ๋์ ) | |
| -- attempts : ์ ์ถ ๊ธฐ๋ก (ํ ๋ฌธ์ ์ ์ฌ๋ฌ ๋ฒ ์ ์ถ ๊ฐ๋ฅ) | |
| -- --------------------------------------------------------------------- | |
| create table if not exists study_sessions ( | |
| id uuid primary key default gen_random_uuid(), | |
| student_id uuid not null references profiles(id) on delete cascade, | |
| session_date date not null, | |
| unit_id text not null references units(unit_id), | |
| status session_status not null default 'in_progress', | |
| min_required smallint not null default 3, -- ํ๋ฃจ ์ต์ ๋ฌธ์ ์ | |
| time_limit_sec integer not null default 900, -- ์ ์ฌ 15๋ถ | |
| started_at timestamptz not null default now(), | |
| ended_at timestamptz, | |
| unique (student_id, session_date, unit_id) | |
| ); | |
| create index if not exists idx_sessions_student_date on study_sessions (student_id, session_date); | |
| create index if not exists idx_sessions_date on study_sessions (session_date); | |
| create table if not exists session_questions ( | |
| id uuid primary key default gen_random_uuid(), | |
| session_id uuid not null references study_sessions(id) on delete cascade, | |
| seq smallint not null, -- ์ถ์ ์์ (์ด์ดํ๊ธฐ ๊ธฐ์ค) | |
| question_id uuid not null references questions(id), | |
| phase step_phase not null default 'ladder', | |
| stage difficulty not null, -- ์ด๋ ๋์ด๋ ๋จ๊ณ์์ ๋์๋์ง | |
| retry_of uuid references session_questions(id), -- ์ฌ๋์ ์ด๋ฉด ์๋ ๋ฌธํญ ํ | |
| outcome step_outcome not null default 'pending', | |
| resolved_at timestamptz, -- ํ๋ฆฐ ๋ฌธ์ ๋ฅผ ์ฌ๋์ ์ผ๋ก ๋งํ ์๊ฐ | |
| created_at timestamptz not null default now(), | |
| unique (session_id, seq), | |
| check (phase = 'ladder' or retry_of is not null) | |
| ); | |
| create index if not exists idx_sq_session on session_questions (session_id); | |
| create index if not exists idx_sq_question on session_questions (question_id); | |
| create table if not exists attempts ( | |
| id uuid primary key default gen_random_uuid(), | |
| session_question_id uuid not null references session_questions(id) on delete cascade, | |
| student_id uuid not null references profiles(id) on delete cascade, -- ์กฐํ ํธ์์ฉ ์ค๋ณต ์ ์ฅ | |
| submitted_answer text, | |
| is_correct boolean not null, | |
| time_spent_sec integer, | |
| scratch_path text, -- ํ์ด ์ค์ผ์น ์ด๋ฏธ์ง(Storage ๊ฒฝ๋ก) | |
| created_at timestamptz not null default now() | |
| ); | |
| create index if not exists idx_attempts_sq on attempts (session_question_id); | |
| create index if not exists idx_attempts_student on attempts (student_id, created_at); | |
| -- --------------------------------------------------------------------- | |
| -- 5. ์๋ด / ์ผ์ ์์ธ | |
| -- --------------------------------------------------------------------- | |
| create table if not exists counseling_notes ( | |
| id uuid primary key default gen_random_uuid(), | |
| student_id uuid not null references profiles(id) on delete cascade, | |
| teacher_id uuid not null references profiles(id), | |
| reason text not null, | |
| note text, | |
| follow_up_on date, | |
| created_at timestamptz not null default now() | |
| ); | |
| create index if not exists idx_counseling_student on counseling_notes (student_id, created_at); | |
| create table if not exists calendar_exceptions ( | |
| exception_date date primary key, -- ํ๊ต ํ์ฌ ๋ฑ ๋ฃจํด ๋ฉด์ ์ผ | |
| title text not null | |
| ); | |
| -- --------------------------------------------------------------------- | |
| -- 6. ๊ต์ฌ ๋์๋ณด๋์ฉ ๋ทฐ: ํ์ x ๋ ์ง x ๋จ์ ์์ฝ | |
| -- unresolved_count = ํ๋ ธ๊ณ ์์ง ์ฌ๋์ ์ผ๋ก ํด๊ฒฐํ์ง ๋ชปํ ๋ฌธ์ ์ | |
| -- --------------------------------------------------------------------- | |
| create or replace view v_student_day_unit | |
| with (security_invoker = true) as | |
| select | |
| s.id as session_id, | |
| s.student_id, | |
| s.session_date, | |
| s.unit_id, | |
| s.status, | |
| count(*) filter (where sq.phase = 'ladder' and sq.outcome <> 'pending') as answered_count, | |
| count(*) filter (where sq.phase = 'ladder' and sq.outcome = 'correct') as correct_count, | |
| count(*) filter (where sq.phase = 'ladder' and sq.outcome = 'wrong' and sq.resolved_at is null) as unresolved_count | |
| from study_sessions s | |
| left join session_questions sq on sq.session_id = s.id | |
| group by s.id; | |
| -- --------------------------------------------------------------------- | |
| -- 7. RLS (ํ ์์ค ๋ณด์) | |
| -- --------------------------------------------------------------------- | |
| create or replace function my_role() | |
| returns user_role language sql stable security definer set search_path = public as $$ | |
| select role from public.profiles where id = auth.uid() | |
| $$; | |
| create or replace function is_teacher_of(target_student uuid) | |
| returns boolean language sql stable security definer set search_path = public as $$ | |
| select exists ( | |
| select 1 | |
| from public.class_members cm | |
| join public.classes c on c.id = cm.class_id | |
| where cm.student_id = target_student | |
| and c.homeroom_teacher_id = auth.uid() | |
| ) | |
| $$; | |
| alter table areas enable row level security; | |
| alter table units enable row level security; | |
| alter table unit_areas enable row level security; | |
| alter table unit_prerequisites enable row level security; | |
| alter table profiles enable row level security; | |
| alter table classes enable row level security; | |
| alter table class_members enable row level security; | |
| alter table questions enable row level security; | |
| alter table question_reports enable row level security; | |
| alter table study_sessions enable row level security; | |
| alter table session_questions enable row level security; | |
| alter table attempts enable row level security; | |
| alter table counseling_notes enable row level security; | |
| alter table calendar_exceptions enable row level security; | |
| -- ๊ต์ก๊ณผ์ ๋ง์คํฐ/์ผ์ : ๋ก๊ทธ์ธํ ์ฌ์ฉ์๋ ์ฝ๊ธฐ ๊ฐ๋ฅ | |
| drop policy if exists read_areas on areas; | |
| create policy read_areas on areas for select to authenticated using (true); | |
| drop policy if exists read_units on units; | |
| create policy read_units on units for select to authenticated using (true); | |
| drop policy if exists read_unit_areas on unit_areas; | |
| create policy read_unit_areas on unit_areas for select to authenticated using (true); | |
| drop policy if exists read_unit_prereq on unit_prerequisites; | |
| create policy read_unit_prereq on unit_prerequisites for select to authenticated using (true); | |
| drop policy if exists read_cal_exc on calendar_exceptions; | |
| create policy read_cal_exc on calendar_exceptions for select to authenticated using (true); | |
| -- ํ๋กํ: ๋ณธ์ธ / ๋ด์๊ต์ฌ / ๊ด๋ฆฌ์ | |
| drop policy if exists read_profiles on profiles; | |
| create policy read_profiles on profiles for select to authenticated | |
| using (id = auth.uid() or is_teacher_of(id) or my_role() = 'admin'); | |
| -- ํ๊ธ (classes <-> class_members ๊ฐ ์๋ก ์ฐธ์กฐํ๋ฉด ์ ์ฑ ๋ฌดํ ์ฌ๊ท๊ฐ ๋๋ฏ๋ก | |
| -- RLS ๋ฅผ ์ฐํํ๋ security definer ํจ์๋ก ํ์ ํฉ๋๋ค) | |
| create or replace function is_class_member(cid uuid) | |
| returns boolean language sql stable security definer set search_path = public as $$ | |
| select exists (select 1 from public.class_members where class_id = cid and student_id = auth.uid()) | |
| $$; | |
| create or replace function is_homeroom_of(cid uuid) | |
| returns boolean language sql stable security definer set search_path = public as $$ | |
| select exists (select 1 from public.classes where id = cid and homeroom_teacher_id = auth.uid()) | |
| $$; | |
| drop policy if exists read_classes on classes; | |
| create policy read_classes on classes for select to authenticated | |
| using (homeroom_teacher_id = auth.uid() or my_role() = 'admin' or is_class_member(id)); | |
| drop policy if exists read_class_members on class_members; | |
| create policy read_class_members on class_members for select to authenticated | |
| using (student_id = auth.uid() or my_role() = 'admin' or is_homeroom_of(class_id)); | |
| -- ๋ฌธ์ ์ํ(questions): authenticated ์ฉ ์ ์ฑ ์ ๋ง๋ค์ง ์์ => service_role ๋ง ์ ๊ทผ | |
| -- ํ์ต ๊ธฐ๋ก: ๋ณธ์ธ / ๋ด์๊ต์ฌ / ๊ด๋ฆฌ์ ์ฝ๊ธฐ (์ฐ๊ธฐ๋ Gradio ์๋ฒ์ service_role ๋ง) | |
| drop policy if exists read_sessions on study_sessions; | |
| create policy read_sessions on study_sessions for select to authenticated | |
| using (student_id = auth.uid() or is_teacher_of(student_id) or my_role() = 'admin'); | |
| drop policy if exists read_session_questions on session_questions; | |
| create policy read_session_questions on session_questions for select to authenticated | |
| using (exists ( | |
| select 1 from study_sessions s | |
| where s.id = session_questions.session_id | |
| and (s.student_id = auth.uid() or is_teacher_of(s.student_id) or my_role() = 'admin') | |
| )); | |
| drop policy if exists read_attempts on attempts; | |
| create policy read_attempts on attempts for select to authenticated | |
| using (student_id = auth.uid() or is_teacher_of(student_id) or my_role() = 'admin'); | |
| -- ์ค๋ฅ ์ ๊ณ : ๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ์์ฑ, ๋ณธ์ธ/๊ด๋ฆฌ์๊ฐ ์กฐํ | |
| drop policy if exists insert_reports on question_reports; | |
| create policy insert_reports on question_reports for insert to authenticated | |
| with check (reporter_id = auth.uid()); | |
| drop policy if exists read_reports on question_reports; | |
| create policy read_reports on question_reports for select to authenticated | |
| using (reporter_id = auth.uid() or my_role() = 'admin'); | |
| -- ์๋ด ๊ธฐ๋ก: ๋ด์๊ต์ฌ(์๊ธฐ ํ์) / ๊ด๋ฆฌ์. ํ์์๊ฒ๋ ๋น๊ณต๊ฐ | |
| drop policy if exists read_counseling on counseling_notes; | |
| create policy read_counseling on counseling_notes for select to authenticated | |
| using ((my_role() = 'teacher' and is_teacher_of(student_id)) or my_role() = 'admin'); | |
| drop policy if exists insert_counseling on counseling_notes; | |
| create policy insert_counseling on counseling_notes for insert to authenticated | |
| with check (teacher_id = auth.uid() and my_role() = 'teacher' and is_teacher_of(student_id)); | |