camper/deploy/add_amenity_feature.sql
jordi fita mas eeaa3b415e Add amenities section and public page
This is more or less the same as the campsites, as public information
goes, but for buildings and other amenities that the camping provides
that are not campsites.
2024-01-27 22:51:41 +01:00

31 lines
808 B
PL/PgSQL

-- Deploy camper:add_amenity_feature to pg
-- requires: roles
-- requires: schema_camper
-- requires: amenity_feature
-- requires: amenity
begin;
set search_path to camper, public;
create or replace function add_amenity_feature(company_id integer, amenity_label text, icon_name text, name text) returns integer as
$$
insert into amenity_feature (amenity_id, icon_name, name)
select amenity_id, icon_name, add_amenity_feature.name
from amenity
where label = amenity_label
and company_id = add_amenity_feature.company_id
union all
select -1, 'baby', 'name'
limit 1
returning amenity_feature_id
;
$$
language sql
;
revoke execute on function add_amenity_feature(integer, text, text, text) from public;
grant execute on function add_amenity_feature(integer, text, text, text) to admin;
commit;