camper/deploy/translate_amenity.sql

28 lines
918 B
MySQL
Raw Permalink Normal View History

-- Deploy camper:translate_amenity to pg
-- requires: roles
-- requires: schema_camper
-- requires: amenity_i18n
begin;
set search_path to camper, public;
create or replace function translate_amenity(amenity_id integer, lang_tag text, name text, info1 text, info2 text) returns void as
$$
insert into amenity_i18n (amenity_id, lang_tag, name, info1, info2)
values (amenity_id, lang_tag, case trim(name) when '' then null else name end, case trim(info1) when '' then null else xmlparse(content info1) end, case trim(info2) when '' then null else xmlparse(content info2) end)
on conflict (amenity_id, lang_tag)
do update
set name = excluded.name
, info1 = excluded.info1
, info2 = excluded.info2
;
$$
language sql
;
revoke execute on function translate_amenity(integer, text, text, text, text) from public;
grant execute on function translate_amenity(integer, text, text, text, text) to admin;
commit;