-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_notes_migration.sql
More file actions
46 lines (38 loc) · 1.65 KB
/
Copy pathsupabase_notes_migration.sql
File metadata and controls
46 lines (38 loc) · 1.65 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- ============================================================
-- CortexNotes: Notes History & Sharing Migration
-- Run this in Supabase SQL Editor after supabase_schema.sql
-- ============================================================
-- Notes table: stores generated study materials per user
create table public.notes (
id uuid default gen_random_uuid() primary key,
user_id uuid references public.users(id) on delete cascade not null,
slug text unique not null,
title text not null default 'Untitled Note',
filename text,
markdown text not null,
quiz jsonb default '[]'::jsonb,
flashcards jsonb default '[]'::jsonb,
is_public boolean default false not null,
created_at timestamptz default now() not null,
creator_name text
);
-- Enable Row Level Security
alter table public.notes enable row level security;
-- Owner can view their own notes
create policy "Users can view own notes" on public.notes
for select using (auth.uid() = user_id);
-- Anyone can view public notes (for sharing)
create policy "Anyone can view public notes" on public.notes
for select using (is_public = true);
-- Owner can create notes
create policy "Users can create own notes" on public.notes
for insert with check (auth.uid() = user_id);
-- Owner can update their notes
create policy "Users can update own notes" on public.notes
for update using (auth.uid() = user_id);
-- Owner can delete their notes
create policy "Users can delete own notes" on public.notes
for delete using (auth.uid() = user_id);
-- Indexes for fast lookups
create index idx_notes_slug on public.notes(slug);
create index idx_notes_user_id_created on public.notes(user_id, created_at desc);