Skip to content

Rentals and contracts

A rental links one driver to at most one car over a period; the car is empty while the rental is pending. A rental has one or more contracts: a renewal at the same rate adds a contract that points at the one it renews, and a rate change starts a new rental.

Scroll a wide diagram sideways to see all of it.

Tables from elsewhere appear as names only: contract_templates, drivers, pools, vehicles.

erDiagram
  rentals {
    uuid id PK
    uuid pool_id FK
    uuid driver_id FK
    uuid vehicle_id FK
    date starts_on
    date ends_on
    bigint driver_daily_rate
    bigint company_daily_cost
    billing_frequency billing_frequency
    date billing_ends_on
    rental_status status
    return_reason end_reason
    jsonb legacy_data
  }
  contracts {
    uuid id PK
    text number
    uuid rental_id FK
    uuid template_id FK
    agreement_status status
    date effective_on
    int2 term_months
    date ends_on
    bigint admin_fee
    bigint daily_rate
    billing_frequency billing_frequency
    text document_path
    text signed_file_path
    timestamptz driver_signed_at
    uuid company_signed_by FK
    timestamptz company_signed_at
    uuid renews_contract_id FK
    timestamptz legacy_updated_at
  }
  pools ||--o{ rentals : "pool_id"
  drivers ||--o{ rentals : "driver_id"
  vehicles |o--o{ rentals : "vehicle_id"
  rentals ||--o{ contracts : "rental_id"
  contract_templates ||--o{ contracts : "template_id"
  contracts |o--o{ contracts : "renews_contract_id"

rentals.legacy_data and contracts.legacy_updated_at hold v1-only data that the migration writes and nothing in v2 reads (D84): v1's audit row for a chain row that begins at a fee change (R-RNT-69), and v1's last edit of a contract (R-RNT-70). No API role writes them (R-RNT-71).