-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
65 lines (58 loc) · 2.48 KB
/
Copy pathschema.sql
File metadata and controls
65 lines (58 loc) · 2.48 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- Create Profiles table (linked to Auth)
create table profiles (
id uuid references auth.users not null primary key,
email text,
full_name text,
avatar_url text,
role text check (role in ('seeker', 'community', 'venue')) default 'seeker',
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- Create Venues table
create table venues (
id bigint generated by default as identity primary key,
name text not null,
location text not null,
sports text,
description text,
image_url text,
owner_id uuid references auth.users,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- Create Events table
create table events (
id bigint generated by default as identity primary key,
title text not null,
sport text not null,
date text not null, -- Storing as text for MVP simplicity
location text not null,
price text,
level text,
participants_count int default 1,
max_participants int default 4,
image_url text,
creator_id uuid references auth.users,
venue_id bigint references venues(id),
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
is_featured boolean default false
);
-- Create Participants table (Many-to-Many)
create table participants (
id bigint generated by default as identity primary key,
event_id bigint references events(id) not null,
user_id uuid references auth.users not null,
joined_at timestamp with time zone default timezone('utc'::text, now()) not null,
unique(event_id, user_id)
);
-- Enable Row Level Security (RLS)
alter table profiles enable row level security;
alter table venues enable row level security;
alter table events enable row level security;
alter table participants enable row level security;
-- Create Policies (Open for MVP)
create policy "Public profiles are viewable by everyone." on profiles for select using (true);
create policy "Users can insert their own profile." on profiles for insert with check (auth.uid() = id);
create policy "Venues are viewable by everyone." on venues for select using (true);
create policy "Events are viewable by everyone." on events for select using (true);
create policy "Participants are viewable by everyone." on participants for select using (true);
create policy "Authenticated users can create events." on events for insert with check (auth.role() = 'authenticated');
create policy "Authenticated users can join events." on participants for insert with check (auth.role() = 'authenticated');