-- Revert camper:campsite_type_cost__-min_nights from pg

begin;

set search_path to camper, public;

alter table campsite_type_cost
add column if not exists min_nights integer not null default 1 constraint at_least_one_night check(min_nights > 0)
;

update campsite_type_cost
set min_nights = lower(bookable_nights)
from campsite_type
where campsite_type.campsite_type_id = campsite_type_cost.campsite_type_id
;

alter table campsite_type_cost
alter column min_nights drop default
;

commit;
