forked from supaflare/supaflare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
36 lines (29 loc) · 1.2 KB
/
database.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
33
34
35
36
create table links (
id uuid default uuid_generate_v4() primary key,
user_id uuid references auth.users not null,
url text check (char_length(url) <= 2083) not null,
slug varchar(50) check (char_length(url) > 0) unique not null,
meta json default '{}' not null,
updated_at timestamp with time zone default timezone('utc' :: text, now()) not null,
inserted_at timestamp with time zone default timezone('utc' :: text, now()) not null
);
alter table
links enable row level security;
create policy "Users can create their own links." on links for
insert
with check (auth.uid() = user_id);
create policy "Users can only view their own links. " on links for
select
using (auth.uid() = user_id);
create policy "Users can only update their own links." on links for
update
using (auth.uid() = user_id);
create policy "Users can only delete their own links." on links for delete using (auth.uid() = user_id);
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON links FOR EACH ROW EXECUTE PROCEDURE update_modified_column();