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