1
0
Fork 0
fahrPool/supabase/migrations/20260704092843_profiles.sql

32 lines
800 B
PL/PgSQL

create type public.app_role as enum ('admin', 'disponent', 'fahrer', 'readonly');
create table public.profiles (
id uuid primary key references auth.users (id) on delete cascade,
name text not null,
role public.app_role not null default 'readonly',
created_at timestamptz not null default now()
);
alter table public.profiles enable row level security;
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = public
as $$
begin
insert into public.profiles (id, name, role)
values (
new.id,
coalesce(new.raw_user_meta_data ->> 'name', new.email),
'readonly'
);
return new;
end;
$$;
create trigger on_auth_user_created
after insert on auth.users
for each row execute function public.handle_new_user();