-- Deploy numerus:build_cookie to pg
-- requires: schema_numerus
-- requires: current_user_email
-- requires: current_user_cookie

begin;

set search_path to numerus, public;

create or replace function build_cookie(user_email email default null, user_cookie text default null) returns text as
$$
	select coalesce(user_cookie, current_user_cookie()) || '/' || coalesce(user_email, current_user_email());
$$
language sql
stable;

revoke execute on function build_cookie(email, text) from public;
grant execute on function build_cookie(email, text) to guest;
grant execute on function build_cookie(email, text) to invoicer;
grant execute on function build_cookie(email, text) to admin;

comment on function build_cookie(email, text) is
'Build the cookie to send to the user’s browser, either for the given values or for the current user.';

commit;
