2023-10-06 11:26:01 +00:00
|
|
|
-- Deploy camper:add_campsite_type_option to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_camper
|
|
|
|
-- requires: campsite_type_option
|
|
|
|
-- requires: campsite_type
|
2024-02-11 20:45:00 +00:00
|
|
|
-- requires: campsite_type_option__per_night
|
2023-10-06 11:26:01 +00:00
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
2024-02-11 20:45:00 +00:00
|
|
|
drop function if exists add_campsite_type_option(uuid, text, integer, integer);
|
|
|
|
|
|
|
|
create or replace function add_campsite_type_option(type_slug uuid, name text, min integer, max integer, per_night boolean) returns integer as
|
2023-10-06 11:26:01 +00:00
|
|
|
$$
|
2024-02-11 20:45:00 +00:00
|
|
|
insert into campsite_type_option (campsite_type_id, name, range, per_night)
|
|
|
|
select campsite_type_id, add_campsite_type_option.name, int4range(min, max, '[]'), per_night
|
2023-10-06 11:26:01 +00:00
|
|
|
from campsite_type
|
|
|
|
where slug = type_slug
|
|
|
|
returning campsite_type_option_id
|
|
|
|
;
|
|
|
|
$$
|
|
|
|
language sql
|
|
|
|
;
|
|
|
|
|
2024-02-11 20:45:00 +00:00
|
|
|
revoke execute on function add_campsite_type_option(uuid, text, integer, integer, boolean) from public;
|
|
|
|
grant execute on function add_campsite_type_option(uuid, text, integer, integer, boolean) to admin;
|
2023-10-06 11:26:01 +00:00
|
|
|
|
|
|
|
commit;
|