-- Deploy camper:add_campsite to pg -- requires: roles -- requires: schema_camper -- requires: campsite -- requires: campsite_type begin; set search_path to camper, public; create or replace function add_campsite(campsite_type integer, label text) returns uuid as $$ declare campsite_slug uuid; begin insert into campsite (company_id, campsite_type_id, label) select company_id, campsite_type_id, label from campsite_type where campsite_type_id = add_campsite.campsite_type returning slug into campsite_slug ; if campsite_slug is null then raise foreign_key_violation using message = 'insert or update on table "campsite" violates foreign key constraint "campsite_campsite_type_id_fkey"'; end if; return campsite_slug; end $$ language plpgsql ; revoke execute on function add_campsite(integer, text) from public; grant execute on function add_campsite(integer, text) to admin; commit;