Operations
One table holds all five kinds of inspection, each with items, photos and damages. A return opens one work order, which leads to maintenance records or an insurance claim. One gate pass is one trip, IN and OUT, with one approval per failing aspect. The weekly ETLE job writes one scan per car; a violation is linked to the rental active at the time.
Scroll a wide diagram sideways to see all of it.
Inspections
Section titled “Inspections”Tables from elsewhere appear as names only: body_panels, charges, gate_passes, inspection_item_types, pools, rentals, vehicles, work_orders.
erDiagram
inspections {
uuid id PK
uuid pool_id FK
uuid vehicle_id FK
uuid rental_id FK
inspection_kind kind
timestamptz inspected_at
uuid inspector_id FK
int odometer_km
int2 fuel_level
int2 battery_pct
return_reason return_reason
inspection_outcome outcome
text bastk_number
uuid gate_pass_id FK
text inspector_sign_path
text driver_sign_path
text notes
text document_path
jsonb legacy_data
}
inspection_items {
uuid id PK
uuid inspection_id FK
uuid item_type_id FK
item_grade grade
bool present
text value
text note
}
inspection_damages {
uuid id PK
uuid inspection_id FK
uuid panel_id FK
text description
text photo_path
bool charge_driver
uuid charge_decided_by FK
text charge_note
uuid work_order_id FK
uuid charge_id FK
}
inspection_photos {
uuid id PK
uuid inspection_id FK
photo_kind kind
uuid damage_id FK
text storage_path
timestamptz taken_at
}
pools ||--o{ inspections : "pool_id"
vehicles ||--o{ inspections : "vehicle_id"
rentals |o--o{ inspections : "rental_id"
gate_passes |o--o{ inspections : "gate_pass_id"
inspections ||--o{ inspection_items : "inspection_id"
inspection_item_types ||--o{ inspection_items : "item_type_id"
inspections ||--o{ inspection_damages : "inspection_id"
body_panels ||--o{ inspection_damages : "panel_id"
work_orders |o--o{ inspection_damages : "work_order_id"
charges |o--o{ inspection_damages : "charge_id"
inspections ||--o{ inspection_photos : "inspection_id"
inspection_damages |o--o{ inspection_photos : "damage_id"
Work orders, maintenance and insurance claims
Section titled “Work orders, maintenance and insurance claims”Tables from elsewhere appear as names only: drivers, garages, inspections, insurance_policies, insurer_garages, insurers, pools, vehicles.
erDiagram
work_orders {
uuid id PK
uuid pool_id FK
uuid vehicle_id FK
uuid inspection_id FK
return_reason reason
text legacy_reason
wo_route route
wo_status status
uuid pic_id FK
timestamptz opened_at
timestamptz ready_at
uuid ready_by FK
}
work_order_events {
uuid id PK
uuid work_order_id FK
wo_action action
uuid actor_id FK
text note
timestamptz at
}
maintenance_records {
uuid id PK
uuid vehicle_id FK
uuid work_order_id FK
uuid garage_id FK
maintenance_kind kind
maintenance_mode mode
priority_level priority
text problem
text action
bigint estimated_cost
bigint actual_cost
int odometer_km
int next_service_km
date started_on
date completed_on
}
insurance_claims {
uuid id PK
text claim_code
uuid vehicle_id FK
uuid policy_id FK
uuid insurer_id FK
uuid garage_id FK
uuid driver_id FK
date accident_on
laka_type severity
claim_category category
int2 panel_count
bigint driver_share
claim_status status
uuid work_order_id FK
date spk_on
date in_garage_on
date completed_on
}
pools ||--o{ work_orders : "pool_id"
vehicles ||--o{ work_orders : "vehicle_id"
inspections |o--o{ work_orders : "inspection_id"
work_orders ||--o{ work_order_events : "work_order_id"
vehicles ||--o{ maintenance_records : "vehicle_id"
work_orders |o--o{ maintenance_records : "work_order_id"
garages |o--o{ maintenance_records : "garage_id"
vehicles ||--o{ insurance_claims : "vehicle_id"
insurance_policies |o--o{ insurance_claims : "policy_id"
insurers |o--o{ insurance_claims : "insurer_id"
garages |o--o{ insurance_claims : "garage_id"
drivers |o--o{ insurance_claims : "driver_id"
work_orders |o--o{ insurance_claims : "work_order_id"
insurer_garages |o--o{ insurance_claims : "insurer_id, garage_id"
Tables from elsewhere appear as names only: pools, rentals, vehicles, work_orders.
erDiagram
gate_passes {
uuid id PK
uuid pool_id FK
uuid vehicle_id FK
text plate_text
uuid rental_id FK
uuid work_order_id FK
gate_pass_kind kind
timestamptz in_at
uuid in_by FK
timestamptz out_at
uuid out_by FK
bigint snap_debt
int2 snap_cp_days
bool snap_service_due
text notes
}
gate_pass_approvals {
uuid id PK
uuid gate_pass_id FK
gate_aspect aspect
uuid approved_by FK
timestamptz approved_at
}
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"
gate_passes ||--o{ gate_pass_approvals : "gate_pass_id"
Tables from elsewhere appear as names only: charges, rentals, vehicles.
erDiagram
etle_scans {
uuid id PK
uuid vehicle_id FK
text plate_checked
timestamptz scanned_at
etle_scan_result result
text error
}
etle_violations {
uuid id PK
uuid vehicle_id FK
uuid rental_id FK
uuid scan_id FK
text ticket_no
timestamptz violated_at
text location
text violation
bigint amount
text photo_path
text detail_url
etle_status status
etle_payer payer
uuid charge_id FK
}
vehicles ||--o{ etle_scans : "vehicle_id"
vehicles ||--o{ etle_violations : "vehicle_id"
rentals |o--o{ etle_violations : "rental_id"
etle_scans |o--o{ etle_violations : "scan_id"
charges |o--o{ etle_violations : "charge_id"