Skip to content

Instantly share code, notes, and snippets.

@gaurangrshah
Created April 7, 2021 00:42
Show Gist options
  • Save gaurangrshah/cd6c0af014c499ff65c06ba40cf6115b to your computer and use it in GitHub Desktop.
Save gaurangrshah/cd6c0af014c499ff65c06ba40cf6115b to your computer and use it in GitHub Desktop.
sql snippets used for supabase
-- inserts a row into public.users
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.users (id)
values (new.id);
return new;
end;
$$ language plpgsql security definer;
-- 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();
create table users (
id uuid references auth.users not null primary key,
email text
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment