-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_registrations.sql
More file actions
28 lines (23 loc) · 1.01 KB
/
Copy pathsetup_registrations.sql
File metadata and controls
28 lines (23 loc) · 1.01 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
-- Create registration table
create table if not exists public.event_registrations (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users(id) on delete cascade not null,
event_id uuid references public.events(id) on delete cascade not null,
created_at timestamptz default now(),
unique(user_id, event_id)
);
-- Enable RLS
alter table public.event_registrations enable row level security;
-- Policies
-- 1. Users can register themselves
create policy "Users can register themselves"
on public.event_registrations for insert
with check (auth.uid() = user_id);
-- 2. Users can view their own registrations
create policy "Users can view their own registrations"
on public.event_registrations for select
using (auth.uid() = user_id);
-- 3. Admins can view all registrations (optional, good for dashboard)
create policy "Admins can view all registrations"
on public.event_registrations for select
using (exists (select 1 from public.roles where user_id = auth.uid() and role = 'admin'));