-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-schema.sql
More file actions
64 lines (53 loc) · 2.05 KB
/
Copy pathsupabase-schema.sql
File metadata and controls
64 lines (53 loc) · 2.05 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- ============================================================
-- EasyNote Supabase Schema
-- Run this in Supabase Dashboard → SQL Editor
-- ============================================================
-- 1. flags table
create table if not exists public.flags (
id uuid primary key,
user_id uuid not null references auth.users(id) on delete cascade,
name text not null,
current integer not null default 0,
total integer not null default 10,
unit text not null default '次',
color text not null default 'blue',
cycle text not null default 'none',
history text[] not null default '{}',
reminder jsonb,
sort_order integer not null default 0,
updated_at timestamptz not null default now()
);
create index if not exists idx_flags_user_id on public.flags(user_id);
-- 2. memos table (one row per user)
create table if not exists public.memos (
user_id uuid primary key references auth.users(id) on delete cascade,
mode text not null default 'note',
text text not null default '',
todos jsonb not null default '[]',
updated_at timestamptz not null default now()
);
-- 3. Enable Row Level Security
alter table public.flags enable row level security;
alter table public.memos enable row level security;
-- 4. RLS Policies: users can only access their own data
create policy "Users can select own flags"
on public.flags for select
using (auth.uid() = user_id);
create policy "Users can insert own flags"
on public.flags for insert
with check (auth.uid() = user_id);
create policy "Users can update own flags"
on public.flags for update
using (auth.uid() = user_id);
create policy "Users can delete own flags"
on public.flags for delete
using (auth.uid() = user_id);
create policy "Users can select own memo"
on public.memos for select
using (auth.uid() = user_id);
create policy "Users can insert own memo"
on public.memos for insert
with check (auth.uid() = user_id);
create policy "Users can update own memo"
on public.memos for update
using (auth.uid() = user_id);