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).
Links with no foreign key (aggregate boundaries)
| Column | Points at | Why there is no FK |
|---|---|---|
reservation_allocations.bin_id | bins.id | Denormalised 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.sku | product_classifications.sku | A SKU does not need a classification — unclassified SKUs are valid and fail open (ADR 0009). |
reservations.demand_ref | an order line in order-management | Another bounded context's identity; stored opaquely, never parsed. |
reservations.line_no | the order's line number in order-management | Another 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_ref | reservations.demand_ref | Not 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_progress | any aggregate row | Infrastructure tables; written in the same transaction as the aggregate change, never joined to it. |
transfer_allocations.reservation_id | reservations.id | Ledger 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_id | reservations.id | Copied 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_id | a transfer in network-inventory-planning | Another 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_id | a slot plan and its assignments in slotting-optimization; bins.id | Another 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_id | reservations.id; a transfer in network-inventory-planning | The 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_id | stock_units.id | The 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_no | a receipt line in inbound-receiving | Another bounded context's identity, carried on ReceiptLineReceived events; stored opaquely (ADR 0045). |
pack_levels.gtin, pack_levels.child_gtin | a GTIN in product-master | Local 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
| Table | Kind | Maps to |
|---|---|---|
stock_units | aggregate root | stock.StockUnit |
bins | aggregate root | location.Bin |
reservations | aggregate root | reservation.Reservation |
reservation_allocations | part of an aggregate | reservation.Allocation values inside Reservation — saved and loaded with it by postgres.ReservationRepo |
product_classifications | aggregate root | product.ProductClassification |
outbox_events | infrastructure — transactional outbox | postgres.OutboxPublisher / OutboxRelay (ADR 0017); published rows pruned by the sweeper after OUTBOX_RETENTION (ADR 0026) |
idempotency_keys | infrastructure — HTTP idempotency | RequireIdempotencyKey middleware (ADR 0018); pruned after IDEMPOTENCY_KEY_TTL |
processed_events | infrastructure — inbound CloudEvents dedupe | postgres.ProcessedEventRepo (ADR 0034, ADR 0035); claim inserted in the same transaction as the effect; not swept |
order_pick_progress | infrastructure — per-order completed-PICK counter, the ADR 0035 counting fallback | postgres.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_migrations | infrastructure — golang-migrate | migration version per database |
pack_levels | read model — product-master packaging projection | the PackagingView, fed by ProductPackLevelDeclared/Retired (ADR 0046); keyed by GTIN, retired levels stay resolvable |
containers | aggregate root | container.Container — the LPN aggregate (ADR 0045); 1:1 with a SEALED_CASE stock_units row |
receipt_line_bookings | infrastructure — booked-quantity record | what ReceiptLineReceived booked per (receipt, line); bounds container creation (ADR 0045 section 6) |
container_pending_links | infrastructure — quarantine | sealed cartons not yet linkable to a Container; re-evaluated when the booking or pack level arrives; REJECTED rows kept for audit |
transfer_allocations | infrastructure — idempotent transfer-decision ledger | one row per transfer_line_id; the unique constraint routes replays to the original outcome (transfer-safe allocation, Phase 2) |
transfer_allocation_releases | infrastructure — 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) |
relocations | infrastructure — immutable relocation record | one row per applied RelocateStock (ADR 0039, migration 0036) |
bin_sku_levels | infrastructure — per-(bin, SKU, owner) version counter | the version behind BinStockLevelChanged, bumped inside the ledger transaction (ADR 0040, migrations 0037, 0038) |
forward_pick_face_plans | read model — slotting-optimization's applied plan per site | the 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_faces | read model — slotting-optimization's forward-slot map | the full sku → bin_id assignment map of the site's applied plan, replaced wholesale; ReserveStock draws these bins first (ADR 0050) |
transfer_receipts | infrastructure — destination receipt ledger | one row per arrived transfer line; STAGED → STOWED; over/short variance explicit on the row (ADR 0031) |
inventory_exceptions | infrastructure — quarantine | destination scans not matched to an ALLOCATED line; no stock row, no usable change, no availability event |
analytics_processed_events | analytics projection | projection idempotency + freshness (GET /reports/flow-accuracy/freshness) |
analytics_consumed_events | analytics projection | consumer-level dedupe (report.ProcessedEvents) |
flow_accuracy_rollup | analytics projection | report.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.