orders table
The orders table in the Reddit Clone Database Schema schema has 11 columns, keyed by id, with 2 foreign keys to users and payment_methods. 1 column in order_items references it.
Money in minor units as an integer beside an explicit currency. Never floats. A refund is a new row referencing the original, never a mutation of it.
Columns (11)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| kind | order_kind | not null | |
| amount_minor | integer | not null | |
| currency | char(3) | not null | |
| status | order_status | not null | |
| payment_method_id | uuid | references payment_methods.id | |
| processor | varchar(40) | not null | |
| processor_reference | varchar(120) | ||
| created_at | timestamptz | not null | |
| completed_at | timestamptz |
Indexes (3)
(user_id, created_at)(status, created_at)(processor_reference)
Relationships
orders.user_idreferencesusers.idorders.payment_method_idreferencespayment_methods.idorder_items.order_idreferencesorders