Skip to content

Add exclusion constraints for driver, tractor, and trailer assignment overlap prevention #472

Description

@emoss08

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

Metadata

Metadata

Assignees

Labels

backendclientgoPull requests that update go code

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions