Entity-relationship diagram
This page is a copy of docs/docs/ddd/entity-relationship.md on develop, derived from that repository's code. Edit it there, then re-sync.
Two separate PostgreSQL databases, each migrated by golang-migrate at startup:
- OLTP (
DATABASE_URL, migrated overMIGRATIONS_DATABASE_URLwhen set — ADR-0031) —migrations/0001to0024, applied bycmd/execution. - Analytics (
ANALYTICS_DATABASE_URL) —migrations/analytics/0001and0002, applied bycmd/fulfillment-projectorand read bycmd/fulfillment-reports(ADR-0012).
Without DATABASE_URL, cmd/execution runs on the in-memory adapters and
none of this exists.
There is not a single FOREIGN KEY in either schema, so the diagrams
draw no relationship lines. 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 0024)
Source: migrations/0001_init.up.sql to migrations/0024_pack_view_dims_package_container.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. |
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 |
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 |