db/schema/0302_default_grps.sql
Orion Kindel 4a81f5fbde
Some checks failed
migrate-devel / migrate-devel (push) Failing after 7s
migrate-stage / migrate-stage (push) Failing after 8s
feat: human uid
2023-07-15 22:17:16 -04:00

29 lines
681 B
PL/PgSQL

create function public.do_usr_create_default_grp()
returns trigger
volatile
language plpgsql
as $$
declare
new_grp int;
begin
insert into public.grp (tag)
values (grp_tag_of_string('usr_' || new.uid))
returning id into new_grp;
perform public.grp_add_member(to_grp => new_grp, add_usr => new.id);
update public.perm
set owner_user = (public.usr_root()).id
, owner_group = (public.grp_admins()).id
where path = '/groups/' || new_grp || '/members'
or path = '/groups/' || new_grp || '/tag';
return null;
end;
$$;
create trigger usr_create_default_grp
after insert on public.usr
for each row
execute function public.do_usr_create_default_grp();