Entity-relationship diagram
Two separate PostgreSQL databases, each migrated by golang-migrate at startup:
- OLTP (
DATABASE_URL, migrated overMIGRATIONS_DATABASE_URLwhen set — ADR-0031) —migrations/0001to0028, applied bycmd/execution,cmd/mcpandcmd/a2a(each runs the migrations at boot). - Analytics (
ANALYTICS_DATABASE_URL) —migrations/analytics/0001and0002, applied bycmd/fulfillment-projectorand read bycmd/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.
Logical links without a foreign key
| From | To | Why there is no FK |
|---|---|---|
packages.task_id | tasks.id | Package 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_id | tasks.id | A 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_id | stations.id | Held by id; the one-open-batch-per-station rule is the partial unique index work_batches_one_open_per_station. |
tasks.lease_station_id | stations.id | The lease names its owner by id; a station can be re-registered without touching tasks. |
tasks.order_ref, packages.order_ref, order_consolidations.order_ref | upstream work_unit_id | Not a table here at all — an opaque id from wes-work-planning. |
product_classification_copy.sku, pack_view.gtin / .sku | product-master | Local copies fed by ProductClassified and ProductPackLevelDeclared / ProductPackLevelRetired events (ADR-0039, ADR-0054); the producer owns the keys. |
interleaving_hints.station_id | stations.id | Local 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_claims | tasks, stations | Different database; built only from events. |
Table ≠ aggregate
| Table | Aggregate / role | Kind |
|---|---|---|
tasks | task.Task (the Lease value object is flattened into lease_station_id + lease_expiry) | aggregate |
stations | station.Station | aggregate |
packages | pack.Package | aggregate |
order_consolidations | consolidation.OrderConsolidation | aggregate |
work_batches | workbatch.WorkBatch, the aggregate root: one station's pick walk (ADR-0063); with PICK_BATCH_MODE off (the fleet default) no row is ever written | aggregate |
work_batch_members | the 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_copy | local copy of product-master's classifications, read by SealPackage's ProductClassificationLookup (ADR-0039) | local copy |
interleaving_hints | local copy of task-interleaving's advisory hints, read by claimNext as a tie-break (ADR-0051) | local copy |
pack_view | local 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_events | transactional outbox, drained by the relay in cmd/execution (ADR-0020) | infrastructure |
processed_events | inbox dedupe for the WorkReleased consumer (ports.ProcessedEvents) | infrastructure |
idempotency_keys | Idempotency-Key replay store for POST /tasks (ADR-0028) | infrastructure |
schema_migrations | golang-migrate version table (one per database) | infrastructure |
throughput_rollup | throughput and on-time-to-CPT projection (ADR-0026) | analytics projection |
analytics_pending_claims | claim times waiting for a completion | analytics projection state |
analytics_processed_events | projection idempotency and freshness | analytics infrastructure |
analytics_consumed_events | consumer-level dedupe for the analytics consumer | analytics infrastructure |