camper/deploy/set_campsite_type_cost.sql

37 lines
1.4 KiB
MySQL
Raw Permalink Normal View History

2023-10-01 19:14:39 +00:00
-- Deploy camper:set_campsite_type_cost to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_cost
-- requires: parse_price
-- requires: campsite_type__bookable_nights
-- requires: campsite_type_cost__per_age
2023-10-01 19:14:39 +00:00
begin;
set search_path to camper, public;
drop function if exists set_campsite_type_cost(uuid, integer, integer, text, integer);
create or replace function set_campsite_type_cost(slug uuid, season_id integer, per_night text, per_adult text, per_teenager text, per_child text) returns void as
2023-10-01 19:14:39 +00:00
$$
insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, cost_per_adult, cost_per_teenager, cost_per_child)
select campsite_type_id, season_id, parse_price(per_night, decimal_digits), parse_price(per_adult, decimal_digits), parse_price(per_teenager, decimal_digits), parse_price(per_child, decimal_digits)
2023-10-01 19:14:39 +00:00
from campsite_type
join company using (company_id)
join currency using (currency_code)
2023-10-01 19:14:39 +00:00
where campsite_type.slug = set_campsite_type_cost.slug
on conflict (campsite_type_id, season_id) do update
set cost_per_night = excluded.cost_per_night
, cost_per_adult = excluded.cost_per_adult
, cost_per_teenager = excluded.cost_per_teenager
, cost_per_child = excluded.cost_per_child
2023-10-01 19:14:39 +00:00
;
$$
language sql
;
revoke execute on function set_campsite_type_cost(uuid, integer, text, text, text, text) from public;
grant execute on function set_campsite_type_cost(uuid, integer, text, text, text, text) to admin;
2023-10-01 19:14:39 +00:00
commit;