-- Deploy camper:add_campsite_type_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_carousel
-- requires: campsite_type

begin;

set search_path to camper, public;

create or replace function add_campsite_type_carousel_slide(slug uuid, media_id integer, caption text) returns integer as
$$
	insert into campsite_type_carousel (campsite_type_id, media_id, caption)
	select campsite_type_id, add_campsite_type_carousel_slide.media_id, coalesce(caption, '')
	from campsite_type
	where slug = add_campsite_type_carousel_slide.slug
	on conflict (campsite_type_id, media_id) do update
	set caption = excluded.caption
	returning campsite_type_id
	;
$$
	language sql
;

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

commit;
