E-commerce Database Schema database schema
The E-commerce Database Schema database schema by Colton Bristow has 36 tables (customers, customer_addresses, wishlists, wishlist_items and 32 more), 236 columns and 46 relationships, documented column by column.
- Tables
- 36
- Columns
- 236
- Relationships
- 46
- Enums
- 12
Tables (36)
| Table | Columns | Description |
|---|---|---|
| customers | 6 | One row per shopper. Guest checkout still creates a customer, flagged by a null password elsewhere in your auth store. |
| customer_addresses | 10 | The customer address book. Orders do not point here, they copy it. See order_addresses. |
| wishlists | 5 | |
| wishlist_items | 3 | |
| product_reviews | 8 | One review per customer per product. rating is constrained to 1-5 by a check constraint. |
| brands | 4 | |
| categories | 5 | Self-referencing tree. parent_id null means a top-level department. |
| products | 8 | The marketing-level item. Nothing is bought or stocked at this level, only at product_variants. |
| product_categories | 2 | A product may sit in several categories. |
| product_options | 4 | The axes a product varies on, e.g. Size and Colour. |
| product_option_values | 4 | The allowed values on one axis, e.g. Small, Medium, Large. |
| product_variants | 10 | The sellable, stockable unit. Carts, orders and inventory all reference this, never products. |
| variant_option_values | 2 | Pins a variant to one value per option. Medium plus Blue resolves to exactly one variant. |
| product_images | 6 | variant_id null means the image belongs to the product as a whole. |
| warehouses | 5 | |
| inventory_items | 6 | Sellable stock is on_hand minus reserved. Reserved rises when an order is placed, on_hand falls when it ships. |
| inventory_movements | 7 | Append-only ledger. quantity is signed. inventory_items.on_hand is the running total and can always be rebuilt from here. |
| carts | 7 | customer_id null is an anonymous cart, tracked by session_token until sign-in merges it. |
| cart_items | 5 | No price column on purpose. A cart always reprices against the live variant. |
| orders | 12 | Every money column is a snapshot taken at placed_at. Totals are stored, not recomputed on read. |
| order_lines | 11 | sku and title are copied, not joined. A renamed product must not change what an old invoice says was bought. |
| order_addresses | 11 | A frozen copy of the address at checkout. Editing the address book never rewrites shipping history. |
| shipments | 8 | An order can ship in several parcels, from several warehouses. |
| shipment_lines | 4 | Quantities here sum to at most the matching order_line quantity. That is what makes partial shipment work. |
| returns | 7 | |
| return_lines | 5 | restock false covers damaged goods, which come back but never re-enter sellable stock. |
| refunds | 8 | Refunds are their own rows. Never subtract from payments.amount_cents. |
| payment_methods | 8 | Display fragments and a processor token only. Raw card data never touches this database. |
| payments | 8 | |
| discounts | 11 | value is a percentage for percentage type, otherwise minor units. currency only applies to fixed-amount discounts. |
| discount_redemptions | 6 | The per-customer index is what enforces one-use-per-shopper promotions. |
| gift_cards | 8 | |
| gift_card_transactions | 5 | Signed ledger, same shape as inventory_movements. balance_cents is the running total. |
| shipping_zones | 3 | country_codes is a comma-separated or array column depending on your engine. |
| shipping_rates | 9 | Null bounds mean unbounded. A free-shipping-over-X rule is price_cents 0 with min_order_cents set. |
| tax_rates | 5 | Basis points, so 8.25 percent is 825. Integer arithmetic all the way through. |
Enums (12)
- product_status
- draft, active, archived
- address_type
- billing, shipping
- review_status
- pending, published, rejected
- cart_status
- active, converted, abandoned
- order_status
- pending, paid, partially_fulfilled, fulfilled, cancelled, refunded
- shipment_status
- pending, in_transit, delivered, failed
- return_status
- requested, approved, received, rejected, closed
- payment_status
- pending, authorized, captured, failed, voided
- refund_status
- pending, succeeded, failed
- discount_type
- percentage, fixed_amount, free_shipping
- inventory_movement_type
- receipt, sale, return, adjustment, transfer
- gift_card_status
- active, redeemed, expired, cancelled
Document your own schema
This page is published from DB Planner, a collaborative ER diagram tool. Write the schema in the DBML editor or import it from SQL, then publish docs like these from the project's sharing settings.