-- Deploy camper:campsite_type__bookable_nights to pg
-- requires: campsite_type
-- requires: campsite_type_cost

begin;

set search_path to camper, public;

alter table campsite_type
add column bookable_nights int4range not null default '[1, 8)' constraint at_least_one_night check (not isempty(bookable_nights) and lower(bookable_nights) > 0)
;

update campsite_type
set bookable_nights = int4range(min_nights, 8)
from campsite_type_cost
where campsite_type_cost.campsite_type_id = campsite_type.campsite_type_id
;

--alter table campsite_type_cost
--drop column if exists min_nights
--;

alter table campsite_type
alter column bookable_nights drop default
;

commit;
