-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
mirror-2/supabase/migrations/20240929043655_spaces_assets.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
create table spaces ( | ||
id uuid not null primary key, | ||
name text not null, | ||
creator_user_id uuid references auth.users(id) on delete cascade not null, | ||
created_at timestamp with time zone not null default now(), | ||
updated_at timestamp with time zone not null default now(), | ||
constraint name_length check (char_length(name) >= 3) | ||
); | ||
|
||
-- add RLS | ||
alter table spaces | ||
enable row level security; | ||
|
||
-- Policy for space owners | ||
create policy "Owners can view their own spaces" | ||
on spaces | ||
for select | ||
using (creator_user_id = auth.uid()); | ||
|
||
-- Policy for creating spaces | ||
create policy "Users can create their own spaces" | ||
on spaces | ||
for insert | ||
with check (creator_user_id = auth.uid()); | ||
|
||
-- Policy for selecting spaces | ||
create policy "Users can view their own spaces" | ||
on spaces | ||
for select | ||
using ( | ||
creator_user_id = auth.uid() | ||
); | ||
|
||
-- Policy for updating spaces | ||
create policy "Users can update their own spaces" | ||
on spaces | ||
for update | ||
using (creator_user_id = auth.uid()); | ||
|
||
-- Policy for deleting spaces | ||
create policy "Users can delete their own spaces" | ||
on spaces | ||
for delete | ||
using (creator_user_id = auth.uid()); | ||
|
||
-- assets | ||
create table assets ( | ||
id uuid not null primary key, | ||
name text not null, | ||
asset_url text not null, | ||
created_at timestamp with time zone not null default now(), | ||
updated_at timestamp with time zone not null default now() | ||
); | ||
|
||
-- add RLS | ||
alter table assets | ||
enable row level security; | ||
|
||
-- set up storage for assets | ||
insert into | ||
storage.buckets (id, name, public) | ||
values | ||
('assets', 'assets', true); |