-- Deploy camper:translate_campsite_feature to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_feature_i18n

begin;

set search_path to camper, public;

create or replace function translate_campsite_feature(feature_id integer, lang_tag text, name text) returns void as
$$
	insert into campsite_feature_i18n (campsite_feature_id, lang_tag, name)
	values (feature_id, lang_tag, case trim(name) when '' then null else name end)
	on conflict (campsite_feature_id, lang_tag) do update
	set name = excluded.name
	;
$$
	language sql
;

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

commit;