-- Deploy camper:remove_amenity_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: amenity_carousel
-- requires: amenity_carousel_i18n

begin;

set search_path to camper, public;

create or replace function remove_amenity_carousel_slide(company_id integer, label text, media_id integer) returns void as
$$
declare
	csid integer;
begin
	select amenity_id
	into csid
	from amenity
	where amenity.label = remove_amenity_carousel_slide.label
	  and amenity.company_id = remove_amenity_carousel_slide.company_id
	;

	delete from amenity_carousel_i18n
	where amenity_id = csid
	  and amenity_carousel_i18n.media_id = remove_amenity_carousel_slide.media_id
	;

	delete from amenity_carousel
	where amenity_id = csid
	  and amenity_carousel.media_id = remove_amenity_carousel_slide.media_id
	;
end
$$
	language plpgsql
;

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

commit;
