Skip to content

Commit

Permalink
chore: Add database migration scripts for username migration and hand…
Browse files Browse the repository at this point in the history
…ling new users (#20)
  • Loading branch information
nphivu414 authored Jun 26, 2024
1 parent af85c1e commit 1d250ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
UPDATE profiles AS p
SET username = u.email
FROM auth.users as u
WHERE p.id = u.id AND p.username IS NULL;
17 changes: 17 additions & 0 deletions supabase/migrations/20240626065226_update_handle_new_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
begin
insert into public.profiles (id, full_name, avatar_url, username)
values (
new.id,
new.raw_user_meta_data->>'full_name',
new.raw_user_meta_data->>'avatar_url',
new.email
);
return new;
end;
$function$
;

0 comments on commit 1d250ee

Please sign in to comment.