-- Deploy camper:booking__stay to pg
-- requires: booking

begin;

set search_path to camper, public;

alter table booking
add column stay daterange constraint stay_not_empty check (not isempty(stay))
;

update booking
set stay = daterange(arrival_date, departure_date)
;

alter table booking
  drop column if exists arrival_date
, drop column if exists departure_date
, alter column stay set not null
;

create index stay_idx on booking using gist (stay);

commit;