-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add database migration scripts for username migration and hand…
…ling new users (#20)
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
supabase/migrations/20240626065103_migrate_username_from_email.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,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
17
supabase/migrations/20240626065226_update_handle_new_user.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,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$ | ||
; |