orders table
The orders table in the E-commerce Database Schema schema has 12 columns, keyed by id, with 1 foreign key to customers. 7 columns in order_lines, order_addresses, shipments, returns and 3 more reference it.
Every money column is a snapshot taken at placed_at. Totals are stored, not recomputed on read.
Columns (12)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| customer_id | uuid | not null, references customers.id | |
| number | varchar(32) | unique, not null | |
| status | order_status | not null | |
| currency | char(3) | not null | |
| subtotal_cents | integer | not null | |
| discount_cents | integer | not null | |
| shipping_cents | integer | not null | |
| tax_cents | integer | not null | |
| total_cents | integer | not null | |
| placed_at | timestamptz | not null | |
| cancelled_at | timestamptz |
Indexes (2)
(customer_id, placed_at)(status, placed_at)
Relationships
orders.customer_idreferencescustomers.idorder_lines.order_idreferencesordersorder_addresses.order_idreferencesordersshipments.order_idreferencesordersreturns.order_idreferencesorderspayments.order_idreferencesordersdiscount_redemptions.order_idreferencesordersgift_card_transactions.order_idreferencesorders