000007_add_booking_exclusion_constraint.up.sql 381 B

12345678
  1. -- Add exclusion constraint to prevent overlapping bookings for the same place
  2. -- Only applies to non-cancelled bookings
  3. ALTER TABLE bookings ADD CONSTRAINT no_overlapping_bookings
  4. EXCLUDE USING gist (place_id WITH =, tsrange(start_time, end_time) WITH &&)
  5. WHERE (status != 'cancelled');
  6. -- Create extension for gist index if not exists
  7. CREATE EXTENSION IF NOT EXISTS btree_gist;