National Commerce Docs
Database

Orders & Shipments

How customer orders, their shipment boxes, line items, and recipients are modeled and kept in sync.

This page covers the core fulfillment tables. An Order is a customer purchase. It is fulfilled by one or more Shipments (physical boxes), each holding one or more Line Items (a quantity of one Product SKU). Every Order also points at an End Customer, the person the boxes ship to. Order totals such as label cost are rolled up from Shipments and Line Items by database triggers, so you rarely write those columns directly.

Orders

A customer order. Money and label totals are not entered by hand: they are recomputed from the Order's Shipments and Shipment Line Items whenever those change. shipping_threshold_exceeded flags orders whose shipping cost passed the configured postage threshold.

ColumnTypeNotes
idintegerPK.
Order_NumbertextHuman-readable order number.
Order_Date_Time__Shiphero_timestampOrder date/time from ShipHero.
SubtotalnumericLine item subtotal.
Total_TaxnumericTax total.
Total_DiscountsnumericDiscount total.
Total_PricenumericOrder grand total.
total_label_costnumericSum of Shipment label costs. Default 0. Rolled up by triggers. See label cost.
total_postage_thresholdnumericThe postage threshold applied to this order.
shipping_proceedsnumericShipping revenue collected from the customer.
shipping_threshold_exceededbooleanTrue when shipping passed the threshold. Default false.
shipping_threshold_exceeded_notification_sentbooleanTrue once the crossing notification has been sent. Default false.
fulfillment_expensenumericFulfillment cost. Default 0.0000. Must be >= 0.
End Customer (Amazon buyer)_idinteger→ references End Customer (Amazon buyer).
brandinteger→ references Brands. See brand.
storebigint→ references Stores.
created_at, updated_at, created_by, updated_byauditStandard audit columns.

Automation. total_label_cost and the money totals are recomputed by triggers on Shipments and Shipment Line Items (see below), so treat them as derived. When shipping_threshold_exceeded changes, an AFTER UPDATE trigger (shipping_threshold_exceeded_trigger) posts to an n8n webhook via supabase_functions.http_request so a notification can go out.

Relationships: each Order belongs to one Brand and one Store, and points at one End Customer. It is fulfilled by many Shipments, each of which links back to this Order.

Shipments

One physical box with its own shipping label, tracked by Tracking_ID and priced by Label_Cost. Each Shipment belongs to an Order. The shipping_zone (1..8, with 9 for territories and military addresses) is computed from zone_distance_miles.

ColumnTypeNotes
idintegerPK.
Shipment_NametextBox/shipment name.
Orders_idinteger→ references Orders.
Warehouses_idinteger→ references Warehouses. Ships from this warehouse.
Service_LeveltextCarrier service level.
Tracking_IDtextCarrier tracking number.
Label_CostnumericCost of this box's label. See label cost.
Box_NametextPackaging/box type.
Box_Weight__oz_numericBox weight in ounces.
Box_Length, Box_Width, Box_HeightnumericBox dimensions.
Shipment_Time__Shiphero_timestampShipment time from ShipHero.
zone_typeenumUSER-DEFINED. Postgres enum.
zone_calculation_statusenumUSER-DEFINED. Postgres enum for the zone computation state.
zone_error_detailstextError detail if zone computation failed.
shipping_zoneintegerComputed zone 1..8 (9 = territories/military).
zone_distance_milesnumericDistance used to compute the zone.
zone_calculated_attimestampWhen the zone was last computed.
brandinteger→ references Brands. Must be > 0.
storeinteger→ references Stores.
created_at, updated_at, created_by, updated_byauditStandard audit columns.

zone_type and zone_calculation_status are Postgres enum types (shown as USER-DEFINED in the DDL).

Automation. On insert, trigger_sync_shipment_store (BEFORE INSERT) runs sync_shipment_store() to copy the store from the linked Order. After a Shipment is updated or deleted, trigger_update_orders / trigger_update_orders_on_deleted_shipment recompute the parent Order's rollups (label cost and totals).

Relationships: each Shipment belongs to one Order, one Warehouse, one Store, and one Brand. It contains many Shipment Line Items.

Shipment Line Items

A quantity of one Product SKU inside a Shipment box. This is the line item level of an order's fulfillment.

Legacy sequence name

The primary key uses the sequence "Line items in shipment_id_seq", a leftover from an earlier table rename. It is unrelated to the current table name.

ColumnTypeNotes
idintegerPK.
Line_Item_IdtextSource line item identifier.
Shipments_idinteger→ references Shipments.
product_skuinteger→ references Product SKUs. Must be > 0.
SKU_QuantitybigintQuantity of this SKU in the box.
shipment_tracking_idtextTracking ID copied from the parent Shipment (see automation).
out_from_inventorynumericQuantity drawn from inventory.
counter_for_inventorybooleanInventory counting flag. Default false.
CountedbooleanWhether this line has been counted. Default false.
tmp_correct_line_itembooleanTemporary correction flag. Default false.
brandinteger→ references Brands.
created_at, updated_at, created_by, updated_byauditStandard audit columns.

Automation. After a Line Item is updated or deleted, trigger_update_orders (update_orders_on_new_line_item()) and trigger_update_orders_on_deleted_line_item (update_orders_on_deleted_line_item()) keep the parent Order's totals current. On insert or update, trigger_update_tracking_id_for_shipment_line_item fills shipment_tracking_id from the parent Shipment.

Relationships: each Line Item belongs to one Shipment, references one Product SKU, and carries a Brand. Through its Shipment it rolls up to an Order.

End Customer (Amazon buyer)

The shipping recipient for an Order: the person and address the boxes are delivered to.

ColumnTypeNotes
idintegerPK.
Full_NametextRecipient name.
Address_1textStreet address line 1.
Address_2textStreet address line 2.
CitytextCity.
StatetextState. Standardized by a trigger (see automation).
Zip_CodetextPostal code.
CountrytextCountry.
Order_Date_Time__Shiphero_timestampOrder date/time from ShipHero.
created_at, updated_at, created_by, updated_byauditStandard audit columns.

Automation. standardize_state_on_insert (BEFORE INSERT/UPDATE) normalizes the State value so it is stored in a consistent form.

Relationships: one End Customer can be referenced by many Orders through Orders.End Customer (Amazon buyer)_id.

shipments_queue

Inbound work queue holding raw ShipHero shipment payloads waiting to be turned into Shipments.

ColumnTypeNotes
idbigintPK. Generated always as identity.
payloadjsonbRaw ShipHero shipment payload.
statusenumPostgres enum shipment_processed_status. Defaults to 'new'.
processing_outputtextResult/output from processing.
brandintegerOwning brand.
created_attimestampWhen the payload was queued.

status is the Postgres enum shipment_processed_status, defaulting to 'new'.

Automation. Rows are consumed by the process_shipment_queue() function, which parses each payload and creates the corresponding Shipments. See Automation for the full catalog.

shiphero_orders_export

A flat import/export staging table of ShipHero orders, keyed by shiphero_order_id. It has no foreign keys and is not part of the live Orders relationships. Treat it as staging data.

ColumnTypeNotes
shiphero_order_idbigintPK. ShipHero order id.
order_numbertextOrder number. Not null.
order_date_localtextOrder date, local, as text.
order_date_utctimestampOrder date in UTC.
store_nametextStore name.
statustextOrder status text.
subtotalnumericSubtotal.
shippingnumericShipping amount.
labelsintegerNumber of labels.
citytextCity.
statetextState.
ziptextPostal code.

This table is populated by imports and read for exports; it does not link to Orders, Shipments, or other live tables.

On this page