-- Deploy camper:translate_campsite_type_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type
-- requires: campsite_type_carousel_i18n

begin;

set search_path to camper, public;

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

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

commit;
