-- Deploy camper:setup_location to pg
-- requires: roles
-- requires: schema_camper
-- requires: location

begin;

set search_path to camper, public;

create or replace function setup_location(company integer, directions text, map_embed text, opening_dates text) returns void as
$$
	insert into location (company_id, directions, map_embed, opening_dates)
	values (company, xmlparse(content directions), xmlparse(content map_embed), xmlparse(content opening_dates))
	on conflict (company_id) do update
	set directions = excluded.directions
	  , map_embed = excluded.map_embed
	  , opening_dates = excluded.opening_dates
	;
$$
	language sql
;

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

commit;
