db/schema/0302_default_grps.sql
Orion Kindel c7091e9ed4
Some checks failed
gen-migrations / gen-migrations (push) Failing after 12s
fix: bugs
2023-07-21 00:10:02 -05:00

33 lines
793 B
PL/PgSQL

create function public.do_usr_create_default_grp()
returns trigger
volatile
language plpgsql
as $$
declare
name public.grp_tag := grp_tag_of_string('usr_' || new.uid);
new_grp public.grp;
begin
insert into public.grp
(tag)
values
(name)
returning * into new_grp;
perform public.grp_add_member(to_grp => new_grp.id, add_usr => new.id);
update public.perm
set owner_user = NEW.id
, owner_group = (public.grp_admins()).id
, owner_user_mode = 'r' :: public.perm_mode
where path = '/groups/' || (new_grp.uid :: text) || '/members'
or path = '/groups/' || (new_grp.uid :: text) || '/name';
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();