camper/deploy/translate_campsite_carousel...

29 lines
1.0 KiB
MySQL
Raw Normal View History

-- Deploy camper:translate_campsite_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite
-- requires: campsite_carousel_i18n
begin;
set search_path to camper, public;
create or replace function translate_campsite_carousel_slide(company_id integer, label text, media_id integer, lang_tag text, caption text) returns void as
$$
insert into campsite_carousel_i18n (campsite_id, media_id, lang_tag, caption)
select campsite_id, translate_campsite_carousel_slide.media_id, lang_tag, case trim(caption) when '' then null else caption end
from campsite
where label = translate_campsite_carousel_slide.label
and company_id = translate_campsite_carousel_slide.company_id
on conflict (campsite_id, media_id, lang_tag) do update
set caption = excluded.caption
;
$$
language sql
;
revoke execute on function translate_campsite_carousel_slide(integer, text, integer, text, text) from public;
grant execute on function translate_campsite_carousel_slide(integer, text, integer, text, text) to admin;
commit;