Add exclusion constraints to prevent double-booking of drivers, tractors, and trailers. Application-layer validation alone is insufficient — concurrent requests can pass validation simultaneously and both commit.
Requires
btree_gist extension (covered in TRE-164).
Constraints to add
Driver assignments
ALTER TABLE driver_assignments
ADD CONSTRAINT no_overlapping_driver_assignments
EXCLUDE USING gist (
driver_id WITH =,
int8range(start_time, end_time, '[]') WITH &&
);
Tractor assignments
ALTER TABLE tractor_assignments
ADD CONSTRAINT no_overlapping_tractor_assignments
EXCLUDE USING gist (
tractor_id WITH =,
int8range(start_time, end_time, '[]') WITH &&
);
Trailer assignments
ALTER TABLE trailer_assignments
ADD CONSTRAINT no_overlapping_trailer_assignments
EXCLUDE USING gist (
trailer_id WITH =,
int8range(start_time, end_time, '[]') WITH &&
);
Notes
- Table and column names above are illustrative — adjust to match actual schema
- These constraints enforce at the database level what is currently only validated in the application
- Pairs well with the
no_overlapping_periods constraint added in TRE-163 for fiscal periods
Add exclusion constraints to prevent double-booking of drivers, tractors, and trailers. Application-layer validation alone is insufficient — concurrent requests can pass validation simultaneously and both commit.
Requires
btree_gistextension (covered in TRE-164).Constraints to add
Driver assignments
Tractor assignments
Trailer assignments
Notes
no_overlapping_periodsconstraint added in TRE-163 for fiscal periods