-- Deploy camper:order_code to pg
-- requires: roles
-- requires: schema_camper
-- requires: payment

begin;

set search_path to camper, public;

create or replace function reference(p payment) returns text as
$$
	select lpad(p.payment_id::text, 8, '0') || substring(p.slug::text from 1 for 4);
$$
	language sql
	stable
;

revoke execute on function reference(payment) from public;
grant execute on function reference(payment) to guest;
grant execute on function reference(payment) to employee;
grant execute on function reference(payment) to admin;

commit;
