diff --git a/mirror-2/supabase/migrations/20240929034647_create_user_profiles.sql b/mirror-2/supabase/migrations/20240929034647_create_user_profiles.sql index 8c4c4534..a5d10456 100644 --- a/mirror-2/supabase/migrations/20240929034647_create_user_profiles.sql +++ b/mirror-2/supabase/migrations/20240929034647_create_user_profiles.sql @@ -6,11 +6,12 @@ create type avatar_type as enum ( -- Create a table for public user_profiles create table user_profiles ( id uuid references auth.users on delete cascade not null primary key, - updated_at timestamp with time zone, display_name text unique not null, public_bio text, ready_player_me_url_glb text, avatar_type public.avatar_type null default 'ready_player_me'::avatar_type, + created_at timestamp with time zone not null default now(), + updated_at timestamp with time zone not null default now(), constraint display_name_length check (char_length(display_name) >= 3) ); -- Set up Row Level Security (RLS) @@ -27,22 +28,6 @@ create policy "Users can insert their own profile." on user_profiles create policy "Users can update own profile." on user_profiles for update using ((select auth.uid()) = id); --- This trigger automatically creates a profile entry when a new user signs up via Supabase Auth. --- See https://supabase.com/docs/guides/auth/managing-user-data#using-triggers for more details. -create function public.handle_new_user() -returns trigger -set search_path = '' -as $$ -begin - insert into public.user_profiles (id, display_name) - values (new.id, new.raw_user_meta_data->>'display_name'); - return new; -end; -$$ language plpgsql security definer; -create trigger on_auth_user_created - after insert on auth.users - for each row execute procedure public.handle_new_user(); - -- Set up Storage! insert into storage.buckets (id, name) values ('avatars', 'avatars'); diff --git a/mirror-2/supabase/seed.sql b/mirror-2/supabase/seed.sql index e69de29b..18253825 100644 --- a/mirror-2/supabase/seed.sql +++ b/mirror-2/supabase/seed.sql @@ -0,0 +1,17 @@ +-- Begin a transaction +begin; + +-- Insert users into the auth.users table +insert into auth.users (id, email) +values + ('9b0c9dfc-7f5d-4de5-9f3d-159a063c987a', 'user1@example.com'), + ('b33ea2f6-d0d8-4c9c-87d1-70b1c102a84d', 'user2@example.com'); + +-- Insert profiles into the user_profiles table +insert into public.user_profiles (id, display_name, public_bio, ready_player_me_url_glb) +values + ('9b0c9dfc-7f5d-4de5-9f3d-159a063c987a', 'User One', 'Bio for User One', 'https://example.com/user1.glb'), + ('b33ea2f6-d0d8-4c9c-87d1-70b1c102a84d', 'User Two', 'Bio for User Two', 'https://example.com/user2.glb'); + +-- Commit the transaction +commit;