chore(#15): add migration to add profiles trigger

This commit is contained in:
OllyNicholass
2024-06-19 00:44:43 +01:00
parent 2dc67875d5
commit baa515ca55
@@ -0,0 +1,21 @@
alter table "public"."profiles" add column "email" text;
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
begin
insert into public.profiles (id, full_name, email)
values (new.id, new.raw_user_meta_data->>'full_name', new.email);
return new;
end;
$function$
;
-- trigger the function every time a user is created
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();