Skip to main content

Entity-Relationship Diagram

Two databases, two migration sets, both applied by golang-migrate on boot (postgres.RunMigrations):

  • OLTP (DATABASE_URL, migrations migrations/0001–0014), migrated by cmd/order and by cmd/mcp (through MIGRATIONS_DATABASE_URL, ADR 0029).
  • Analytics (ANALYTICS_DATABASE_URL, migrations migrations/analytics/0001–0003), migrated only by cmd/order-projector; cmd/order-reports and cmd/mcp only 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_id points into inventory-storage's database (a Reservation id) — another bounded context, so no FK is possible or wanted (ADR 0002).
  • order_lines.path_id and planned_capacity_windows.path_id are process-path ids owned by process-path-management / warehouse-planning.
  • order_promise_groups.line_nos refers to order_lines.line_no of the same order, but as an array, so it is enforced in the aggregate (Order.SetPromiseGroups), not by the database.
  • outbox_events.key holds the OrderId as 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_id and shipment_processed_events.event_id hold inbound CloudEvents ids from other contexts. shipment_processed_events (migration 0014, ADR 0051) is keyed by the raw ShipmentConfirmed id with no per-order scoping: one event names many orders and is applied in one transaction. It stays empty while OUTBOUND_SHIPPING_CONSUMER_MODE=off.
  • orders.fulfillment_site_id (migration 0013, ADR 0044) is the optional, caller-assigned site; it is written only by the INSERT of a new order.
  • product_classification_copy.sku is a product-master SKU (ADR 0036): a local copy, never joined to order_lines.sku by a constraint.
  • release_confirmations.(order_id, line_no) names an order line but has no foreign key to orders/order_lines on 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 while RELEASE_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​

TableWhat it isAggregate / owner
ordersAggregate root rowOrder (order.Order)
order_linesEntity rows inside the aggregateOrder — order.OrderLine
order_promise_groupsValue objects of the aggregate (delete-and-reinsert on every save)Order — order.PromiseGroup
planned_capacity_windowsRead model of another context's datanone — order.PlannedCapacityWindow (ADR 0031)
repromise_processed_eventsInfrastructure: inbound idempotency ledgerports.RepromiseProcessedEvents
planned_capacity_processed_eventsInfrastructure: inbound idempotency ledgerports.PlannedCapacityProcessedEvents
product_classification_copyLocal copy of another context's data (product-master, ADR 0036)none — ports.ProductClassificationCopy / ProductClassificationLookup
product_classification_processed_eventsInfrastructure: inbound idempotency ledgerports.ProductClassificationProcessedEvents
release_confirmationsProcess manager: whether wes-work-planning confirmed each released line (ADR 0043); deliberately outside the Order aggregatenone — releaseconfirmation.Confirmation / ports.ReleaseConfirmations
release_confirmation_processed_eventsInfrastructure: inbound idempotency ledgerports.ReleaseConfirmationProcessedEvents
shipment_processed_eventsInfrastructure: inbound idempotency ledger of ShipmentConfirmed (ADR 0051)ports.ShipmentProcessedEvents
outbox_eventsInfrastructure: transactional outbox (ADR 0022)postgres.OutboxPublisher / OutboxRelay
idempotency_keysInfrastructure: HTTP request de-duplication (ADR 0023)inbound/http.RequireIdempotencyKey
schema_migrationsInfrastructure: golang-migrate—
funnel_rollup, repromise_rollupAnalytics projection (ADR 0006/0019)report.Row via cmd/order-projector
analytics_processed_events, analytics_consumed_eventsInfrastructure: projector idempotencyanalyticsstore

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).