-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
32 lines (26 loc) · 1.01 KB
/
schema.sql
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
create table if not exists todos (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
title VARCHAR ( 255 ) NOT NULL,
done BOOL,
user_id VARCHAR (255) NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
-- 1st enable row level security for your table
alter table todos enable row level security;
-- 2nd create policies for your table
create policy "Individuals can create todos." on todos for
insert with check (auth.user_id() = user_id);
create policy "Individuals can view their own todos. " on todos for
select using (auth.user_id() = user_id);
create policy "Individuals can update their own todos." on todos for
update using (auth.user_id() = user_id);
create policy "Individuals can delete their own todos." on todos for
delete using (auth.user_id() = user_id);
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLES
TO authenticated;
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLES
TO anonymous;