Vehicles
A car belongs to a home pool and to a rental company, TOP's being the operator's own (D108), with supply_status for its deal with that company (active, replacing or inactive; V13's contract_status, renamed by D56 in BE pack G2). Former plates stay in vehicle_plate_history; status changes are written to vehicle_status_history by the status function. A car has at most one GPS device, and its insurers over the years are insurance_policies rows. A car's photos, one row per photo with its side, are vehicle_photos rows (D110).
Scroll a wide diagram sideways to see all of it.
Tables from elsewhere appear as names only: insurers, pools, rental_companies, rentals, vehicle_models.
erDiagram
vehicles {
uuid id PK
uuid home_pool_id FK
uuid rental_company_id FK
uuid model_id FK
text unit_code
text plate_number
int2 year
text color
bigint company_daily_cost
int odometer_km
vehicle_status status
supply_status supply_status
}
vehicle_plate_history {
uuid id PK
uuid vehicle_id FK
text plate_number
timestamptz valid_from
timestamptz valid_to
uuid changed_by FK
}
vehicle_documents {
uuid id PK
uuid vehicle_id FK
vehicle_doc_type doc_type
text storage_path
date expires_on
date tax_due_on
}
vehicle_photos {
uuid id PK
uuid vehicle_id FK
vehicle_photo_side side
text storage_path
}
gps_devices {
uuid id PK
uuid vehicle_id FK,UK
text provider
text external_id
text imei
date installed_on
}
gps_positions {
bigint id PK
uuid gps_device_id FK
timestamptz recorded_at
geography location
numeric(6_2) speed_kmh
}
vehicle_status_history {
uuid id PK
uuid vehicle_id FK
vehicle_status from_status
vehicle_status to_status
uuid rental_id FK
uuid changed_by FK
text note
timestamptz changed_at
}
insurance_policies {
uuid id PK
uuid vehicle_id FK
uuid insurer_id FK
text policy_number
text coverage
date starts_on
date ends_on
}
pools ||--o{ vehicles : "home_pool_id"
rental_companies ||--o{ vehicles : "rental_company_id"
vehicle_models ||--o{ vehicles : "model_id"
vehicles ||--o{ vehicle_plate_history : "vehicle_id"
vehicles ||--o{ vehicle_documents : "vehicle_id"
vehicles ||--o{ vehicle_photos : "vehicle_id"
vehicles |o--o| gps_devices : "vehicle_id"
gps_devices ||--o{ gps_positions : "gps_device_id"
vehicles ||--o{ vehicle_status_history : "vehicle_id"
rentals |o--o{ vehicle_status_history : "rental_id"
vehicles ||--o{ insurance_policies : "vehicle_id"
insurers ||--o{ insurance_policies : "insurer_id"