Skip to content

Data model

Schema V13 is the Postgres schema v2 runs on: 70 tables, with row-level security on every one. These diagrams show how the tables link. What each step of the business writes is on Business flow, and the rules each table follows are on the rule pages.

Line end Means
Two bars exactly one
Circle and bar zero or one
Circle and crow's foot zero or more

For example, drivers ||--o{ rentals reads: a rental has exactly one driver, and a driver has zero or more rentals. A circle on the parent's end means the foreign key may be empty, such as a pending rental with no car yet. When both ends show at most one, the foreign key is unique (one-to-one). Each line's label is the column that holds the key.

Left out to keep the drawings readable: organization_id, which every table has (only the overview shows organizations); created_at and updated_at; and, outside Tenancy and access, the staff columns that record who did something (created_by, recorded_by, approved_by and the like, all pointing at profiles). Every table has an id uuid primary key unless it shows another key.

A pool holds drivers and cars. A rental links a driver to at most one car over time, and contracts, inspections and charges point at the rental, so who had the car is never copied as a name. Payments reach charges only through allocations.

erDiagram
  pools ||--o{ drivers : "pool_id"
  drivers |o--o{ drivers : "referred_by_driver_id"
  pools ||--o{ vehicles : "home_pool_id"
  pools ||--o{ rentals : "pool_id"
  drivers ||--o{ rentals : "driver_id"
  vehicles |o--o{ rentals : "vehicle_id"
  rentals ||--o{ contracts : "rental_id"
  contracts |o--o{ contracts : "renews_contract_id"
  pools ||--o{ inspections : "pool_id"
  vehicles ||--o{ inspections : "vehicle_id"
  rentals |o--o{ inspections : "rental_id"
  gate_passes |o--o{ inspections : "gate_pass_id"
  pools ||--o{ work_orders : "pool_id"
  vehicles ||--o{ work_orders : "vehicle_id"
  inspections |o--o{ work_orders : "inspection_id"
  pools ||--o{ gate_passes : "pool_id"
  vehicles |o--o{ gate_passes : "vehicle_id"
  rentals |o--o{ gate_passes : "rental_id"
  work_orders |o--o{ gate_passes : "work_order_id"
  drivers ||--o{ charges : "driver_id"
  rentals |o--o{ charges : "rental_id"
  legal_entities |o--o{ charges : "legal_entity_id"
  drivers ||--o{ payments : "driver_id"
  payments ||--o{ payment_allocations : "payment_id"
  charges ||--o{ payment_allocations : "charge_id"
  charges ||--o{ charge_adjustments : "charge_id"
  drivers ||--o{ debt_letters : "driver_id"
  rentals |o--o{ debt_letters : "rental_id"
  organizations ||--o{ legal_entities : "organization_id"
  organizations ||--o{ pools : "organization_id"