-- Deploy numerus:roles to pg

begin;

do
$$
declare
	role name;
	roles name[] := array['guest', 'invoicer', 'admin', 'authenticator'];
begin
	foreach role in array roles
	loop
		begin
			execute 'create role ' || role || ' noinherit nologin';
		exception
		when duplicate_object then
			raise notice '%, skipping', sqlerrm using errcode = sqlstate;
		end;
	end loop;
end
$$;

grant guest to authenticator;
grant invoicer to authenticator;
grant admin to authenticator;

commit;
