-- Deploy camper:remove_campsite_type_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_carousel
-- requires: campsite_type_carousel_i18n

begin;

set search_path to camper, public;

create or replace function remove_campsite_type_carousel_slide(slug uuid, media_id integer) returns void as
$$
declare
	csid integer;
begin
	select campsite_type_id
	into csid
	from campsite_type
	where campsite_type.slug = $1
	;
	delete from campsite_type_carousel_i18n
	where campsite_type_id = csid
	  and campsite_type_carousel_i18n.media_id = $2
	;
	delete from campsite_type_carousel
	where campsite_type_id = csid
	  and campsite_type_carousel.media_id = $2
	;
end
$$
	language plpgsql
;

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

commit;
