Skip to content

Commit

Permalink
add seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
Kluskey committed Sep 29, 2024
1 parent 0052764 commit db3e9e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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');
Expand Down
17 changes: 17 additions & 0 deletions mirror-2/supabase/seed.sql
Original file line number Diff line number Diff line change
@@ -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', '[email protected]'),
('b33ea2f6-d0d8-4c9c-87d1-70b1c102a84d', '[email protected]');

-- 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;

0 comments on commit db3e9e5

Please sign in to comment.