Schema
The database behind the Availability & Capacity Service and the Delivery Scheduler. Generated from the migration file, so every column shown is one the database actually creates.
Real samples come from the prod_delivery_scheduler export of 16/10/2026, whose IDs and figures come from NetSuite and the WH picking schedule sheet. They follow one truck-day: Bris 01 in Bris R1 (Sunshine Coast) on Wed 7 Oct 2026, 2.2914 of 14 m³ and 5 of 12 stops committed. Tables with no real rows yet use labelled examples. No customer details appear here.
SO123456 example
How the tables connect
Every column except the timestamps. Types, rules and samples are in the tables below. Scrolls sideways on a small screen.
erDiagram
region {
bigint id PK
varchar code UK
varchar name UK
char depot_code
varchar external_id UK
}
postcode {
char postcode PK
bigint region_id FK
}
truck {
bigint id PK
varchar name UK
char depot_code
varchar kind
decimal max_cbm
boolean active
}
courier {
bigint id PK
varchar courier_code UK
varchar name UK
boolean active
}
courier_shipmethod {
bigint id PK
bigint courier_id FK
varchar ns_account UK
varchar netsuite_internal_id UK
}
netsuite_mapping {
bigint id PK
varchar ns_account UK
varchar category UK
varchar internal_id UK
varchar name
}
availability_pattern {
bigint id PK
bigint truck_id FK
bigint region_id FK
tinyint weekday
varchar schedule_role
decimal cbm_capacity
int max_stops
int buffer_days
date valid_from
date valid_to
}
run {
bigint id PK
bigint truck_id FK,UK
date run_date UK
varchar schedule_role
varchar status
varchar status_reason
varchar created_by
varchar updated_by
}
run_region {
bigint id PK
bigint run_id FK,UK
bigint region_id FK
decimal cbm_capacity
int max_stops
int buffer_days
decimal cbm_committed
int stops_committed
bigint region_key UK
}
courier_day {
bigint id PK
bigint courier_id FK,UK
date day UK
varchar status
varchar status_reason
int buffer_days
}
reservation {
bigint id PK
varchar idempotency_key UK
varchar consumer
varchar source
varchar order_ref
bigint run_region_id FK
varchar leg
varchar group_ref
varchar status
datetime held_until
decimal cbm
int stops
char postcode
date delivery_date
date ship_date
varchar truck_name
varchar created_by
}
adhoc_entry {
bigint id PK
varchar order_ref
varchar reason
bigint region_id FK
varchar status
json cartons
varchar created_by
varchar updated_by
}
event {
bigint id PK
datetime occurred_at
varchar actor
varchar kind
varchar subject_type
varchar subject_id
json before
json after
varchar reason
varchar request_id
}
availability_check {
bigint id PK
datetime checked_at
varchar consumer
varchar request_id
varchar order_ref
varchar postcode
decimal order_cbm
date requested_date
int dates_returned
date first_date
varchar outcome
}
region ||--o{ adhoc_entry : "region_id"
truck ||--o{ availability_pattern : "truck_id"
region ||--o{ availability_pattern : "region_id"
courier ||--o{ courier_day : "courier_id"
courier ||--o{ courier_shipmethod : "courier_id"
region ||--o{ postcode : "belongs to"
run_region ||--o{ reservation : "takes capacity"
truck ||--o{ run : "drives"
run ||--o{ run_region : "has regions"
region ||--o{ run_region : "region_id"Tables and columns
Compared with Sushil's schema
For reference only — nothing here is used by this service. 11 tables, 99 columns in
prod_delivery_scheduler today. Columns: prod_delivery_scheduler export, information_schema columns (16/10/2026). Keys: lifeinteriors/lifeinte-fulfillment@effcd25 packages/db/src/schema.ts (read only). Names and types only. No row data.
| Sushil | This schema | What changed | Which is better, and why |
|---|---|---|---|
couriers | courier + courier_shipmethod | Ship-method ids move out of a JSON array on runs into their own table, keyed by NetSuite account + id. | Ours. Holds Life and ES ids side by side (D18); his has Life ids only. |
regions | region (depot code) | Same regions and names. Each region carries its depot code (SYD, MEL, BNE); the time zones live in code. | Ours. "Today" is computed per depot (rule 11; Brisbane has no DST). |
life_trucks | truck | Adds depot code, last-mile/linehaul kind and the physical maximum load. | Ours. Nothing in his stops a run being typed above what the truck can carry (rule 2, Q29). |
postcodes | postcode | Same. | Equal. |
runs | availability_pattern + run + run_region + courier_day | His run is an undated courier × region × truck row. Ours splits it: the weekly plan, the dated truck-day (one per truck per date), capacity per region within that day, and courier operating days. | Ours. His unique (courier, region, truck) cannot stop one truck being booked in three regions on the same day (rule 1). |
run_availability_days | run.status + status_reason · courier_day | Available becomes a status with a mandatory reason when not available. | Ours. A 0 with no reason cannot tell "suspended" from "nobody filled it in" (rule 4). |
run_capacity_days | run_region.cbm_committed / stops_committed + NetSuite read copies | Committed load is changed only by one conditional write, checked against capacity in the database, and split by source. NetSuite load is a read copy refreshed every 30 min (D16). | Ours. His is recalculated wholesale from a snapshot, with no source split (rule 3) and no committed ≤ capacity check (rule 5). |
netsuite_mapping | netsuite_mapping | Adds the NetSuite account. | Ours, slightly. ES ids can sit beside Life ids. |
events | event + availability_check | His logs API traffic and stores every order, names and addresses included, per sync. Ours records decisions (who, before, after, why) and every availability check, with no customer data. | Ours. Rules 9 and 10, and no personal data kept per run. |
adhoc_entries | adhoc_entry + reservation (source adhoc) | Ours keeps order ref, reason, region and status; capacity is taken through a reservation. | His, on one point. He stores the delivery address, contact, dates and carton count. Ours has nowhere for the address the driver needs. Gap to decide (where the address lives, given the no-personal-data-in-logs rule). |
adhoc_entry_cartons | adhoc_entry.cartons | Folded into the entry as a list (D19): SKU or none, qty, length, width, height, kg and m³ per carton. | Equal on content; ours is one table fewer. Cartons are never queried on their own. |
— | reservation | New: an order's claim on capacity — held, confirmed or released, never deleted, idempotent, interstate legs paired, values snapshotted. | Ours. Rules 5–8; nothing in his records who took capacity or lets it be released. |
His tables as they connect
Every column except the timestamps.
erDiagram
couriers {
bigint id PK
varchar name UK
varchar courier_code UK
tinyint active
}
regions {
bigint id PK
varchar name UK
varchar external_id UK
}
life_trucks {
bigint id PK
varchar name UK
tinyint active
}
postcodes {
bigint id PK
varchar postcode UK
bigint region_id FK
}
runs {
bigint id PK
bigint courier_id FK
bigint region_id FK
bigint truck_id FK
json netsuite_internal_ids
decimal cbm_capacity
int max_delivery_stops
int buffer_days
text note
tinyint active
enum schedule_role
enum haul_type
}
run_availability_days {
bigint id PK
bigint run_id FK
date date
tinyint available
varchar source
}
run_capacity_days {
bigint id PK
bigint run_id FK
date date
decimal committed_cbm
int committed_qty
int committed_stops
varchar source
timestamp synced_at
}
netsuite_mapping {
bigint id PK
varchar category
varchar internal_id
varchar name
}
events {
bigint id PK
varchar event_type
varchar identifier
json payload
}
adhoc_entries {
bigint id PK
varchar order_ref
varchar reason
varchar customer_name
varchar phone
varchar street
varchar suburb
varchar postcode
bigint region_id FK
int carton_count
decimal committed_cbm
decimal weight_kg
bigint run_id FK
bigint courier_id FK
bigint truck_id FK
date ship_date
date schedule_delivery_date
bigint line_haul_run_id FK
bigint line_haul_truck_id FK
date line_haul_date
varchar created_by
varchar updated_by
enum status
}
adhoc_entry_cartons {
bigint id PK
bigint adhoc_entry_id FK
int position
decimal length_cm
decimal width_cm
decimal height_cm
decimal weight_kg
decimal committed_cbm
}
regions ||--o{ postcodes : "region_id"
couriers ||--o{ runs : "courier_id"
regions ||--o{ runs : "region_id"
life_trucks ||--o{ runs : "truck_id"
runs ||--o{ run_availability_days : "run_id"
runs ||--o{ run_capacity_days : "run_id"
regions ||--o{ adhoc_entries : "region_id"
runs ||--o{ adhoc_entries : "run_id"
couriers ||--o{ adhoc_entries : "courier_id"
life_trucks ||--o{ adhoc_entries : "truck_id"
runs ||--o{ adhoc_entries : "line_haul_run_id"
life_trucks ||--o{ adhoc_entries : "line_haul_truck_id"
adhoc_entries ||--o{ adhoc_entry_cartons : "adhoc_entry_id"His tables and columns
Open a table to see its columns.
couriers Life and the third-party couriers.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
name | varchar(255) | yes | |||
courier_code | varchar(64) | yes | |||
active | tinyint(1) | yes | 1 | ||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: name; courier_code
regions Life delivery regions, by the name NetSuite uses.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
name | varchar(255) | yes | |||
external_id | varchar(64) | no | |||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: name; external_id
life_trucks Truck and linehaul names. No depot, type or capacity.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
name | varchar(255) | yes | |||
active | tinyint(1) | yes | 1 | ||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: name
postcodes Postcode → region.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
postcode | varchar(10) | yes | |||
region_id | bigint unsigned | yes | FK | → regions | |
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: postcode
runs One row per courier × region × truck: capacity, max stops, buffer, the NetSuite ship-method ids, ship/delivery-date role and last-mile/linehaul. Not dated.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
courier_id | bigint unsigned | yes | FK | → couriers | |
region_id | bigint unsigned | no | FK | → regions | |
truck_id | bigint unsigned | no | FK | → life_trucks | |
netsuite_internal_ids | json | yes | [] | ||
cbm_capacity | decimal(6,2) | no | |||
max_delivery_stops | int | no | |||
buffer_days | int | yes | 0 | ||
note | text | no | |||
active | tinyint(1) | yes | 1 | ||
schedule_role | enum('SHIP_DATE','DELIVERY_DATE') | yes | SHIP_DATE | ||
haul_type | enum('LAST_MILE','LINE_HAUL') | yes | LAST_MILE | ||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: courier_id + region_id + truck_id
run_availability_days Whether a run operates on a date (1/0), synced from the WH picking schedule sheet.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
run_id | bigint unsigned | yes | FK | → runs | |
date | date | yes | |||
available | tinyint(1) | yes | |||
source | varchar(64) | yes | sheet_sync | ||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: run_id + date
run_capacity_days Committed m³, quantity and stops per run per date, recalculated from the NetSuite snapshot.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
run_id | bigint unsigned | yes | FK | → runs | |
date | date | yes | |||
committed_cbm | decimal(10,4) | yes | 0.0000 | ||
committed_qty | int | yes | 0 | ||
committed_stops | int | yes | 0 | ||
source | varchar(64) | yes | netsuite_sync | ||
synced_at | timestamp | yes | now() | ||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: run_id + date
netsuite_mapping Lookups: Detrack truck numbers, linehaul routes, reason codes.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
category | varchar(64) | yes | |||
internal_id | varchar(255) | yes | |||
name | varchar(255) | yes | |||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: category + internal_id
events API request/response log and one JSON snapshot of every order per sync run.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
event_type | varchar(64) | yes | |||
identifier | varchar(255) | yes | |||
payload | json | yes | |||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
adhoc_entries An ad hoc delivery: order ref, reason, customer name, phone, street, postcode, region, run, courier, truck, ship/delivery/linehaul dates, carton count, m³, weight, status.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
order_ref | varchar(64) | yes | |||
reason | varchar(200) | yes | |||
customer_name | varchar(255) | yes | |||
phone | varchar(32) | yes | |||
street | varchar(255) | yes | |||
suburb | varchar(128) | no | |||
postcode | varchar(10) | yes | |||
region_id | bigint unsigned | yes | FK | → regions | |
carton_count | int | yes | |||
committed_cbm | decimal(10,4) | yes | |||
weight_kg | decimal(8,2) | yes | |||
run_id | bigint unsigned | yes | FK | → runs | |
courier_id | bigint unsigned | yes | FK | → couriers | |
truck_id | bigint unsigned | no | FK | → life_trucks | |
ship_date | date | no | |||
schedule_delivery_date | date | no | |||
line_haul_run_id | bigint unsigned | no | FK | → runs | |
line_haul_truck_id | bigint unsigned | no | FK | → life_trucks | |
line_haul_date | date | no | |||
created_by | varchar(255) | yes | |||
updated_by | varchar(255) | yes | |||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() | ||
status | enum('ACTIVE','ON_HOLD','CANCELLED') | yes | ACTIVE |
adhoc_entry_cartons Each carton of an ad hoc entry: length, width, height, weight and m³.
| Column | Type | Required | Default | Key | Links to |
|---|---|---|---|---|---|
id | bigint unsigned | yes | PK | ||
adhoc_entry_id | bigint unsigned | yes | FK | → adhoc_entries | |
position | int | yes | |||
length_cm | decimal(7,2) | yes | |||
width_cm | decimal(7,2) | yes | |||
height_cm | decimal(7,2) | yes | |||
weight_kg | decimal(8,2) | yes | |||
committed_cbm | decimal(10,4) | yes | |||
created_at | timestamp | yes | now() | ||
updated_at | timestamp | yes | now() |
Unique: adhoc_entry_id + position