camper/deploy/add_campsite_type_option@v3.sql
jordi fita mas ea997a4154 Allow campsite type option to be just per unit, not per unit per night
Customer told us that there are some options, such as towels, that have
a fixed price for the whole stay, not a per night price.  Thus, had to
add a boolean to know whether to use sum or max when computing the
cart’s total for each option.
2024-02-11 21:45:00 +01:00

27 lines
773 B
PL/PgSQL

-- Deploy camper:add_campsite_type_option to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_option
-- requires: campsite_type
begin;
set search_path to camper, public;
create or replace function add_campsite_type_option(type_slug uuid, name text, min integer, max integer) returns integer as
$$
insert into campsite_type_option (campsite_type_id, name, range)
select campsite_type_id, add_campsite_type_option.name, int4range(min, max, '[]')
from campsite_type
where slug = type_slug
returning campsite_type_option_id
;
$$
language sql
;
revoke execute on function add_campsite_type_option(uuid, text, integer, integer) from public;
grant execute on function add_campsite_type_option(uuid, text, integer, integer) to admin;
commit;