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.

ER diagram of the E-commerce Database Schema schema, showing 36 tables and their relationships
FIG. 1: entity relationship diagram, 36 tables
Tables
36
Columns
236
Relationships
46
Enums
12

Tables (36)

Tables in the E-commerce Database Schema schema
TableColumnsDescription
customers6One row per shopper. Guest checkout still creates a customer, flagged by a null password elsewhere in your auth store.
customer_addresses10The customer address book. Orders do not point here, they copy it. See order_addresses.
wishlists5
wishlist_items3
product_reviews8One review per customer per product. rating is constrained to 1-5 by a check constraint.
brands4
categories5Self-referencing tree. parent_id null means a top-level department.
products8The marketing-level item. Nothing is bought or stocked at this level, only at product_variants.
product_categories2A product may sit in several categories.
product_options4The axes a product varies on, e.g. Size and Colour.
product_option_values4The allowed values on one axis, e.g. Small, Medium, Large.
product_variants10The sellable, stockable unit. Carts, orders and inventory all reference this, never products.
variant_option_values2Pins a variant to one value per option. Medium plus Blue resolves to exactly one variant.
product_images6variant_id null means the image belongs to the product as a whole.
warehouses5
inventory_items6Sellable stock is on_hand minus reserved. Reserved rises when an order is placed, on_hand falls when it ships.
inventory_movements7Append-only ledger. quantity is signed. inventory_items.on_hand is the running total and can always be rebuilt from here.
carts7customer_id null is an anonymous cart, tracked by session_token until sign-in merges it.
cart_items5No price column on purpose. A cart always reprices against the live variant.
orders12Every money column is a snapshot taken at placed_at. Totals are stored, not recomputed on read.
order_lines11sku and title are copied, not joined. A renamed product must not change what an old invoice says was bought.
order_addresses11A frozen copy of the address at checkout. Editing the address book never rewrites shipping history.
shipments8An order can ship in several parcels, from several warehouses.
shipment_lines4Quantities here sum to at most the matching order_line quantity. That is what makes partial shipment work.
returns7
return_lines5restock false covers damaged goods, which come back but never re-enter sellable stock.
refunds8Refunds are their own rows. Never subtract from payments.amount_cents.
payment_methods8Display fragments and a processor token only. Raw card data never touches this database.
payments8
discounts11value is a percentage for percentage type, otherwise minor units. currency only applies to fixed-amount discounts.
discount_redemptions6The per-customer index is what enforces one-use-per-shopper promotions.
gift_cards8
gift_card_transactions5Signed ledger, same shape as inventory_movements. balance_cents is the running total.
shipping_zones3country_codes is a comma-separated or array column depending on your engine.
shipping_rates9Null bounds mean unbounded. A free-shipping-over-X rule is price_cents 0 with min_order_cents set.
tax_rates5Basis 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.

More published database schemas