Repository navigation
Expand file tree
/
Copy pathsupabase-setup.sql
More file actions
42 lines (35 loc) · 1.52 KB
/
Copy pathsupabase-setup.sql
File metadata and controls
42 lines (35 loc) · 1.52 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
create table if not exists public.workouts (
id uuid primary key,
user_id uuid not null references auth.users(id) on delete cascade,
workout_date date not null,
workout_type text not null,
note text not null default '',
exercises jsonb not null default '[]'::jsonb check (jsonb_typeof(exercises) = 'array'),
updated_at timestamptz not null default now()
);
create index if not exists workouts_user_date_idx
on public.workouts (user_id, workout_date desc);
alter table public.workouts enable row level security;
revoke all on table public.workouts from anon;
grant select, insert, update, delete on table public.workouts to authenticated;
drop policy if exists "Users can read own workouts" on public.workouts;
create policy "Users can read own workouts"
on public.workouts for select
to authenticated
using ((select auth.uid()) = user_id);
drop policy if exists "Users can insert own workouts" on public.workouts;
create policy "Users can insert own workouts"
on public.workouts for insert
to authenticated
with check ((select auth.uid()) = user_id);
drop policy if exists "Users can update own workouts" on public.workouts;
create policy "Users can update own workouts"
on public.workouts for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
drop policy if exists "Users can delete own workouts" on public.workouts;
create policy "Users can delete own workouts"
on public.workouts for delete
to authenticated
using ((select auth.uid()) = user_id);