diff --git a/mirror-2/supabase/migrations/20240929043655_spaces_assets.sql b/mirror-2/supabase/migrations/20240929043655_spaces_assets.sql new file mode 100644 index 00000000..c3694271 --- /dev/null +++ b/mirror-2/supabase/migrations/20240929043655_spaces_assets.sql @@ -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);