Skip to main content

Entity-Relationship Diagram

The schema after applying migrations/0001…0008, 0030…0033 (site custody, transfer ledger, transfer receipts and exceptions, processed_events), 0034 (order_pick_progress), 0035 (reservations.line_no), 0036 (relocations), 0037 (bin_sku_levels), 0038 (containers, owners, packaging), 0039 (forward pick faces) and 0040 (transfer_allocation_releases) (OLTP database, DATABASE_URL) and migrations/analytics/0001 (analytical database, ANALYTICS_DATABASE_URL) in order. Relationship lines are drawn only where a real FOREIGN KEY (REFERENCES) exists in the migrations.

OLTP database​

Source: migrations/0001_init.up.sql … migrations/0008_reservation_allocation_bin_id.up.sql, plus 0030_stock_unit_site_custody.up.sql (stock_units.site_id, bins.site_id), 0031_transfer_allocations_ledger.up.sql (transfer_allocations), 0032_transfer_receipts_and_exceptions.up.sql (transfer_receipts, inventory_exceptions, ADR 0031), 0033_product_master_local_copy.up.sql (processed_events), 0034_order_pick_progress.up.sql (order_pick_progress, ADR 0035), 0035_reservation_line_no.up.sql (reservations.line_no, ADR 0036), 0036_relocations.up.sql (relocations, ADR 0039), 0037_bin_sku_levels.up.sql (bin_sku_levels, ADR 0040) and 0038_containers_owner_stock_packaging.up.sql (pack_levels, containers, receipt_line_bookings, container_pending_links, owner/pack columns on stock_units, reservations, bin_sku_levels, ADR 0045, 0046), 0039_forward_pick_faces.up.sql (forward_pick_face_plans, forward_pick_faces, ADR 0050) and 0040_transfer_allocation_releases.up.sql (transfer_allocation_releases, ADR 0051); schema_migrations is created by golang-migrate (internal/adapters/outbound/postgres/migrate.go). Omitted: the events table created by 0001 — 0005 drops it, so it is not part of the final schema. TEXT_ARRAY stands for Postgres TEXT[] (kept as a plain token so the Mermaid type parses).

ColumnPoints atWhy there is no FK
reservation_allocations.bin_idbins.idDenormalised pick location (ADR 0025), copied from the stock unit at reserve time; nullable for rows the 0008 backfill could not resolve.
stock_units.sku, reservations.skuproduct_classifications.skuA SKU does not need a classification — unclassified SKUs are valid and fail open (ADR 0009).
reservations.demand_refan order line in order-managementAnother bounded context's identity; stored opaquely, never parsed.
reservations.line_nothe order's line number in order-managementAnother bounded context's identity, sent as lineNo on POST /reservations (ADR 0036); nullable (NULL for reservations made before migration 0035 or by a client that does not send it); with demand_ref it identifies the line the consumer confirms.
order_pick_progress.demand_refreservations.demand_refNot unique on reservations (one reservation per order line), and the counter row is swept independently of the reservations; correlated by value only (ADR 0035). Only written by the counting fallback for events or reservations without line_no (ADR 0036).
outbox_events, idempotency_keys, processed_events, order_pick_progressany aggregate rowInfrastructure tables; written in the same transaction as the aggregate change, never joined to it.
transfer_allocations.reservation_idreservations.idLedger row written in the same transaction as the hold; NULL exactly when outcome = REJECTED; a replayed command is answered from the ledger, so the reference is never joined (transfer-safe allocation, Phase 2).
transfer_receipts.reservation_idreservations.idCopied from the allocation ledger; the receipt stages and stows independently of the reservation lifecycle (ADR 0031).
transfer_allocations.transfer_id / transfer_line_id, transfer_receipts.transfer_id / transfer_line_ida transfer in network-inventory-planningAnother bounded context's identity; stored opaquely, transfer_line_id made DB-unique so replays return the original outcome.
forward_pick_face_plans.plan_id, forward_pick_faces.sku / bin_ida slot plan and its assignments in slotting-optimization; bins.idAnother bounded context's identity (SlotPlanApproved.plan_id, assignments[{sku, slot}]) kept by value as a local read model, so bin_id carries no FK to bins (ADR 0050). The only real FK of the pair is forward_pick_faces.site_id → forward_pick_face_plans.site_id (ON DELETE CASCADE); a site's map is replaced wholesale when a later plan is approved.
transfer_allocation_releases.reservation_id, .transfer_id / .transfer_line_idreservations.id; a transfer in network-inventory-planningThe release ledger mirrors transfer_allocations: references held by value, transfer_line_id DB-unique so a replayed TransferAllocationReleaseRequested returns the original outcome (ADR 0051).
containers.stock_unit_idstock_units.idThe 1:1 SEALED_CASE unit, enforced by a unique index, not a FK; NULL until the container's stock unit exists (ADR 0045).
containers.receipt_id / line_no, receipt_line_bookings.receipt_id / line_no, container_pending_links.receipt_id / line_noa receipt line in inbound-receivingAnother bounded context's identity, carried on ReceiptLineReceived events; stored opaquely (ADR 0045).
pack_levels.gtin, pack_levels.child_gtina GTIN in product-masterLocal projection of ProductPackLevelDeclared/Retired; another bounded context's identity, resolvable after retirement (ADR 0046).

Analytical database​

Source: migrations/analytics/0001_report.up.sql. This database is written only by cmd/inventory-projector and read only by cmd/inventory-reports (ADR 0011). It has no foreign keys at all: the rollup is keyed by SKU, bin and hour, and the two event-id tables are idempotency ledgers.

Table ≠ aggregate​

TableKindMaps to
stock_unitsaggregate rootstock.StockUnit
binsaggregate rootlocation.Bin
reservationsaggregate rootreservation.Reservation
reservation_allocationspart of an aggregatereservation.Allocation values inside Reservation — saved and loaded with it by postgres.ReservationRepo
product_classificationsaggregate rootproduct.ProductClassification
outbox_eventsinfrastructure — transactional outboxpostgres.OutboxPublisher / OutboxRelay (ADR 0017); published rows pruned by the sweeper after OUTBOX_RETENTION (ADR 0026)
idempotency_keysinfrastructure — HTTP idempotencyRequireIdempotencyKey middleware (ADR 0018); pruned after IDEMPOTENCY_KEY_TTL
processed_eventsinfrastructure — inbound CloudEvents dedupepostgres.ProcessedEventRepo (ADR 0034, ADR 0035); claim inserted in the same transaction as the effect; not swept
order_pick_progressinfrastructure — per-order completed-PICK counter, the ADR 0035 counting fallbackpostgres.OrderPickProgressRepo (ADR 0035); written only for a PICK without line_no or one served by line-less reservations (ADR 0036), never on the per-line path; incremented in the same transaction as the processed_events claim; rows not updated for ORDER_PICK_PROGRESS_RETENTION (default 30 days) pruned by the sweeper (ADR 0026)
schema_migrationsinfrastructure — golang-migratemigration version per database
pack_levelsread model — product-master packaging projectionthe PackagingView, fed by ProductPackLevelDeclared/Retired (ADR 0046); keyed by GTIN, retired levels stay resolvable
containersaggregate rootcontainer.Container — the LPN aggregate (ADR 0045); 1:1 with a SEALED_CASE stock_units row
receipt_line_bookingsinfrastructure — booked-quantity recordwhat ReceiptLineReceived booked per (receipt, line); bounds container creation (ADR 0045 section 6)
container_pending_linksinfrastructure — quarantinesealed cartons not yet linkable to a Container; re-evaluated when the booking or pack level arrives; REJECTED rows kept for audit
transfer_allocationsinfrastructure — idempotent transfer-decision ledgerone row per transfer_line_id; the unique constraint routes replays to the original outcome (transfer-safe allocation, Phase 2)
transfer_allocation_releasesinfrastructure — idempotent release ledger (cancel-after-allocation compensation)one row per transfer_line_id this service has released; outcome RELEASED or ALREADY_RESOLVED (ADR 0051, migration 0040)
relocationsinfrastructure — immutable relocation recordone row per applied RelocateStock (ADR 0039, migration 0036)
bin_sku_levelsinfrastructure — per-(bin, SKU, owner) version counterthe version behind BinStockLevelChanged, bumped inside the ledger transaction (ADR 0040, migrations 0037, 0038)
forward_pick_face_plansread model — slotting-optimization's applied plan per sitethe supersession guard of the forward map: a plan applies only if its approved_at is later than the held one, or equal with a higher plan_id (ADR 0050)
forward_pick_facesread model — slotting-optimization's forward-slot mapthe full sku → bin_id assignment map of the site's applied plan, replaced wholesale; ReserveStock draws these bins first (ADR 0050)
transfer_receiptsinfrastructure — destination receipt ledgerone row per arrived transfer line; STAGED → STOWED; over/short variance explicit on the row (ADR 0031)
inventory_exceptionsinfrastructure — quarantinedestination scans not matched to an ALLOCATED line; no stock row, no usable change, no availability event
analytics_processed_eventsanalytics projectionprojection idempotency + freshness (GET /reports/flow-accuracy/freshness)
analytics_consumed_eventsanalytics projectionconsumer-level dedupe (report.ProcessedEvents)
flow_accuracy_rollupanalytics projectionreport.Row, the Inventory Flow & Accuracy report

The OLTP processed_events table (migration 0033) is the inbox of the Kafka consumers that must be exactly-once (ApplyProductClassification, ConfirmPicksForOrder); the facility location cache, by contrast, is in memory and rebuilt from offset 0 on every start, with idempotent upserts instead of an id ledger.