camper/deploy/add_amenity_feature.sql

31 lines
808 B
MySQL
Raw Normal View History

-- 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;