-- Deploy camper:add_campsite_feature to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_feature
-- requires: campsite

begin;

set search_path to camper, public;

create or replace function add_campsite_feature(company_id integer, campsite_label text, icon_name text, name text) returns integer as
$$
	insert into campsite_feature (campsite_id, icon_name, name)
	select campsite_id, icon_name, add_campsite_feature.name
	from campsite
	where label = campsite_label
	  and company_id = add_campsite_feature.company_id
	returning campsite_feature_id
	;
$$
	language sql
;

revoke execute on function add_campsite_feature(integer, text, text, text) from public;
grant execute on function add_campsite_feature(integer, text, text, text) to admin;

commit;
