Skip to main content
This page is the complete reference schema. Other pages explain why each table is designed as it is; this page is the authoritative source for names, keys, and constraints, so that prose, SQL, APIs, events, and tests remain consistent. Every table uses UUID primary keys (gen_random_uuid()) to avoid insert hotspots, DECIMAL for money, and TIMESTAMPTZ for time.
[!WARNING] Do not use INTERLEAVE IN PARENT It was removed from CockroachDB. Co-locate related data through key design and hash-sharded indexes, not interleaving.

Entity overview

Core DDL

Fulfillment tables (shipments, shipment_lines, returns, return_lines) are defined on the Fulfillment & returns page.

Conventions

  • Keys: UUID default gen_random_uuid(); child tables use composite PKs (order_id, line_no / order_id, seq).
  • Separate by access pattern: the order header (orders), the immutable line detail (order_lines), and the append-only history (order_events) are separate tables: their read/write patterns differ, and detail and history are write-once.
  • Index for demonstrated queries only: choose primary keys around the dominant lookup path; add a secondary index only when a real query needs it (speculative indexes cost write throughput). Use keyset pagination rather than OFFSET for large scans, and avoid unindexed JSONB filters on hot paths.
  • Money: DECIMAL(18,2) + currency CHAR(3); never FLOAT.
  • Time: TIMESTAMPTZ everywhere.
  • Invariants in the schema: CHECK constraints (available >= 0, refunded_amount <= amount, qty > 0) are backstops that hold even if application code is wrong.
  • Expiry/cleanup: Row-Level TTL on reservations, idempotency_keys, and outbox to garbage-collect, never to enforce correctness.