-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsupabase_notifications.sql
More file actions
32 lines (27 loc) · 1.2 KB
/
supabase_notifications.sql
File metadata and controls
32 lines (27 loc) · 1.2 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
-- Create notifications table
create table if not exists public.notifications (
id bigint generated by default as identity primary key,
user_id uuid references auth.users(id) on delete cascade not null,
sender_id uuid references auth.users(id) on delete set null,
type text check (type in ('like', 'comment', 'save', 'schedule')) not null,
message text not null,
is_read boolean default false,
link text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- Enable RLS
alter table public.notifications enable row level security;
-- Create policies
create policy "Users can view their own notifications"
on public.notifications for select
using (auth.uid() = user_id);
create policy "Users can update their own notifications"
on public.notifications for update
using (auth.uid() = user_id);
create policy "Users can delete their own notifications"
on public.notifications for delete
using (auth.uid() = user_id);
-- Allow anyone (authenticated) to insert notifications (e.g. when liking a post)
create policy "Anyone can insert notifications"
on public.notifications for insert
with check (auth.role() = 'authenticated');