Entity-Relationship Diagram
Two databases, two migration sets, both applied by golang-migrate on boot
(postgres.RunMigrations):
- OLTP (
DATABASE_URL, migrationsmigrations/0001–0014), migrated bycmd/orderand bycmd/mcp(throughMIGRATIONS_DATABASE_URL, ADR 0029). - Analytics (
ANALYTICS_DATABASE_URL, migrationsmigrations/analytics/0001–0003), migrated only bycmd/order-projector;cmd/order-reportsandcmd/mcponly read it.
The diagrams show the final schema after applying every *.up.sql in
order. 0001_init created an events table that 0007_outbox dropped, so
it is not shown.
OLTP database
Source: migrations/0001_init.up.sql … migrations/0014_shipment_processed_events.up.sql;
schema_migrations is golang-migrate's own bookkeeping table
(internal/adapters/outbound/postgres/migrate.go). Omits: secondary
indexes (idx_order_lines_sku, idx_order_lines_status,
idx_outbox_events_unpublished partial on published_at IS NULL,
idx_idempotency_keys_created_at, planned_capacity_windows_location_end,
and the three partial indexes of release_confirmations on
released_at where PENDING, confirmed_at where CONFIRMED and
unconfirmed_at where UNCONFIRMED).
INT_ARRAY stands for Postgres INT[], TEXT_ARRAY for TEXT[], DOUBLE_PRECISION for
DOUBLE PRECISION.
Only two real FOREIGN KEYs exist: order_lines.order_id and
order_promise_groups.order_id, both to orders.id. Everything else is
deliberately unlinked:
order_lines.reservation_idpoints into inventory-storage's database (aReservationid) — another bounded context, so no FK is possible or wanted (ADR 0002).order_lines.path_idandplanned_capacity_windows.path_idare process-path ids owned by process-path-management / warehouse-planning.order_promise_groups.line_nosrefers toorder_lines.line_noof the same order, but as an array, so it is enforced in the aggregate (Order.SetPromiseGroups), not by the database.outbox_events.keyholds theOrderIdas the Kafka key — infrastructure, not a relation.repromise_processed_events.event_id,planned_capacity_processed_events.event_id,product_classification_processed_events.event_id,release_confirmation_processed_events.event_idandshipment_processed_events.event_idhold inbound CloudEvents ids from other contexts.shipment_processed_events(migration 0014, ADR 0051) is keyed by the rawShipmentConfirmedid with no per-order scoping: one event names many orders and is applied in one transaction. It stays empty whileOUTBOUND_SHIPPING_CONSUMER_MODE=off.orders.fulfillment_site_id(migration 0013, ADR 0044) is the optional, caller-assigned site; it is written only by theINSERTof a new order.product_classification_copy.skuis a product-master SKU (ADR 0036): a local copy, never joined toorder_lines.skuby a constraint.release_confirmations.(order_id, line_no)names an order line but has no foreign key toorders/order_lineson purpose (ADR 0043): it records another context's behaviour, never an invariant of the order, and a late or missing confirmation must not touch the order. Both new tables stay empty whileRELEASE_CONFIRMATION_MODE=off.
Analytics database
Source: migrations/analytics/0001_report.up.sql,
0002_promise_kpis.up.sql, 0003_promise_basis_network.up.sql. Omits:
indexes idx_funnel_rollup_hour_bucket,
idx_analytics_processed_events_occurred_at,
idx_repromise_rollup_hour_bucket. There are no foreign keys in this
database: every table is a projection or an idempotency ledger.
analytics_processed_events is claimed inside the projection transaction
(analyticsstore.PostgresProjection) and also drives the freshness lag;
analytics_consumed_events backs the consumer's own
ConsumedEventsRepo.
Table ≠ aggregate
| Table | What it is | Aggregate / owner |
|---|---|---|
orders | Aggregate root row | Order (order.Order) |
order_lines | Entity rows inside the aggregate | Order — order.OrderLine |
order_promise_groups | Value objects of the aggregate (delete-and-reinsert on every save) | Order — order.PromiseGroup |
planned_capacity_windows | Read model of another context's data | none — order.PlannedCapacityWindow (ADR 0031) |
repromise_processed_events | Infrastructure: inbound idempotency ledger | ports.RepromiseProcessedEvents |
planned_capacity_processed_events | Infrastructure: inbound idempotency ledger | ports.PlannedCapacityProcessedEvents |
product_classification_copy | Local copy of another context's data (product-master, ADR 0036) | none — ports.ProductClassificationCopy / ProductClassificationLookup |
product_classification_processed_events | Infrastructure: inbound idempotency ledger | ports.ProductClassificationProcessedEvents |
release_confirmations | Process manager: whether wes-work-planning confirmed each released line (ADR 0043); deliberately outside the Order aggregate | none — releaseconfirmation.Confirmation / ports.ReleaseConfirmations |
release_confirmation_processed_events | Infrastructure: inbound idempotency ledger | ports.ReleaseConfirmationProcessedEvents |
shipment_processed_events | Infrastructure: inbound idempotency ledger of ShipmentConfirmed (ADR 0051) | ports.ShipmentProcessedEvents |
outbox_events | Infrastructure: transactional outbox (ADR 0022) | postgres.OutboxPublisher / OutboxRelay |
idempotency_keys | Infrastructure: HTTP request de-duplication (ADR 0023) | inbound/http.RequireIdempotencyKey |
schema_migrations | Infrastructure: golang-migrate | — |
funnel_rollup, repromise_rollup | Analytics projection (ADR 0006/0019) | report.Row via cmd/order-projector |
analytics_processed_events, analytics_consumed_events | Infrastructure: projector idempotency | analyticsstore |
One Order is persisted as one orders row, N order_lines rows and up
to N order_promise_groups rows, written in one transaction by
postgres.OrderRepo.Save with the version guard (ADR 0024).