Skip to main content

Entity-relationship diagram

Two separate PostgreSQL databases, each migrated by golang-migrate at startup:

  • OLTP (DATABASE_URL, migrated over MIGRATIONS_DATABASE_URL when set — ADR-0031) — migrations/0001 to 0028, applied by cmd/execution, cmd/mcp and cmd/a2a (each runs the migrations at boot).
  • Analytics (ANALYTICS_DATABASE_URL) — migrations/analytics/0001 and 0002, applied by cmd/fulfillment-projector and read by cmd/fulfillment-reports (ADR-0012).

DATABASE_URL is mandatory: there is no in-memory mode (ADR-0052).

There is exactly one FOREIGN KEY in either schema: work_batch_members.batch_id → work_batches.id (ON DELETE CASCADE, migration 0027) — a member row is part of its WorkBatch aggregate and has no meaning without it. Every other link is held by id. The logical links are explained below the diagrams — each one crosses an aggregate boundary, which is exactly why it is held by id and not by a constraint.

OLTP schema (final, after 0028)​

Source: migrations/0001_init.up.sql to migrations/0028_task_order_site_id.up.sql, applied in order; 0018_drop_domain_events removed the legacy domain_events table (ADR-0045); schema_migrations is golang-migrate's own table (internal/adapters/outbound/postgres/migrate.go). Array columns are shown as text_array / integer_array (Postgres TEXT[] / INTEGER[]). Omits indexes other than the ones noted (idx_tasks_type_status_cpt on task_type, status, cpt drives FindClaimableByType) and column defaults.

Analytics schema (final, after analytics 0002)​

Source: migrations/analytics/0001_report.up.sql, migrations/analytics/0002_on_time_to_cpt.up.sql, internal/adapters/outbound/analyticsstore/*.go. Omits column defaults.

FromToWhy there is no FK
packages.task_idtasks.idPackage and Task are separate aggregates; SealPackage checks the task in the application layer. The partial unique index enforces one package per PACK task.
work_batch_members.task_idtasks.idA member is a snapshot of a task at formation (pick face, CPT instant, hazard class); the batch never re-reads the task pool and the two aggregates change in separate transactions (ADR-0063).
work_batches.station_idstations.idHeld by id; the one-open-batch-per-station rule is the partial unique index work_batches_one_open_per_station.
tasks.lease_station_idstations.idThe lease names its owner by id; a station can be re-registered without touching tasks.
tasks.order_ref, packages.order_ref, order_consolidations.order_refupstream work_unit_idNot a table here at all — an opaque id from wes-work-planning.
product_classification_copy.sku, pack_view.gtin / .skuproduct-masterLocal copies fed by ProductClassified and ProductPackLevelDeclared / ProductPackLevelRetired events (ADR-0039, ADR-0054); the producer owns the keys.
interleaving_hints.station_idstations.idLocal copy of task-interleaving's advisory hint (ADR-0051); fail-open — an absent or expired row means "no hint", so no constraint.
throughput_rollup, analytics_pending_claimstasks, stationsDifferent database; built only from events.

Table ≠ aggregate​

TableAggregate / roleKind
taskstask.Task (the Lease value object is flattened into lease_station_id + lease_expiry)aggregate
stationsstation.Stationaggregate
packagespack.Packageaggregate
order_consolidationsconsolidation.OrderConsolidationaggregate
work_batchesworkbatch.WorkBatch, the aggregate root: one station's pick walk (ADR-0063); with PICK_BATCH_MODE off (the fleet default) no row is ever writtenaggregate
work_batch_membersthe batch's member snapshots (workbatch.Member), stored with and only through their WorkBatch; tasks.work_started_at is the per-stop work clock (ADR-0064)aggregate (part)
product_classification_copylocal copy of product-master's classifications, read by SealPackage's ProductClassificationLookup (ADR-0039)local copy
interleaving_hintslocal copy of task-interleaving's advisory hints, read by claimNext as a tie-break (ADR-0051)local copy
pack_viewlocal copy of product-master's pack levels keyed by GTIN, read by the pick scan confirmation (ADR-0054); declared dims and the package container columns come from ship-in-own-container (ADR-0056)local copy
outbox_eventstransactional outbox, drained by the relay in cmd/execution (ADR-0020)infrastructure
processed_eventsinbox dedupe for the WorkReleased consumer (ports.ProcessedEvents)infrastructure
idempotency_keysIdempotency-Key replay store for POST /tasks (ADR-0028)infrastructure
schema_migrationsgolang-migrate version table (one per database)infrastructure
throughput_rollupthroughput and on-time-to-CPT projection (ADR-0026)analytics projection
analytics_pending_claimsclaim times waiting for a completionanalytics projection state
analytics_processed_eventsprojection idempotency and freshnessanalytics infrastructure
analytics_consumed_eventsconsumer-level dedupe for the analytics consumeranalytics infrastructure