camper/deploy/translate_amenity_carousel_...

29 lines
1.0 KiB
MySQL
Raw Normal View History

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