Entity-relationship diagram
The schema below is the final state after applying migrations/0001 to
migrations/0016 in order (golang-migrate, run on start-up by
cmd/wes (DATABASE_URL is mandatory), over MIGRATIONS_DATABASE_URL if given —
ADR-0026), plus the
separate analytical database built from migrations/analytics/.
There is no database-less mode: DATABASE_URL is a boot requirement (ADR-0044). The
in-memory repositories (internal/adapters/outbound/memory) are unit-test
doubles only.
OLTP database
Source: migrations/0001_init.up.sql to migrations/0016_pack_aware_work.up.sql.
Omits: golang-migrate's own schema_migrations bookkeeping table, column
defaults and NOT NULL flags (every column above is NOT NULL except
released_at, completed_at, drift_heads, drift_detected_at,
travel_distance_m, travel_distance_estimated, key,
published_at, last_error, temperature_class, dot_hazard_class,
child_gtin, qty_of_child, the pack-level dimension and measured columns
(length_mm, width_mm, height_mm, weight_g, measured_length_mm,
measured_width_mm, measured_height_mm, measured_weight_g),
effective_to and the idempotency outcome columns).
The only foreign key in the schema is
work_pool_entries.path_id → work_pools.path_id. Everything else is linked
logically, by value, with no constraint — on purpose:
work_pool_entries.work_unit_id↔work_units.id— two aggregates (WorkPool,WorkUnit) referenced by identity. A foreign key would couple their consistency boundaries; the use cases keep them aligned inside one transaction, andWorkPool.Reconcileheals a stale entry.work_units.path_id,labor_plan_view.path_id(and the keptshift_plans.path_id,charge_forecasts.path_id) ↔work_pools.path_id— each is a separate aggregate or projection keyed by the same process-path id, whose catalogue is owned by process-path-management.usable_inventory_view.sku↔work_units.sku— different contexts' keys; inventory-storage owns the SKU.product_classification_copy.sku↔work_units.sku— product-master owns the classification; the copy is fed by itsProductClassifiedevents (ADR-0035).slot_plans.plan_id↔ slotting-optimization's approved plans — the plan is owned by slotting-optimization; the copy records every plan this context applied (or found stale) so a newer plan supersedes an older one whatever order the events arrive in (ADR-0040).product_pack_level_copy.gtin/.sku↔ product-master's pack levels — the copy is fed byProductPackLevelDeclared/Retired/Measuredevents, keyed by 14-digit GTIN (ADR-0045). Neither new table has a foreign key.
Analytics database
A separate database (ANALYTICS_DATABASE_URL), written only by
cmd/wes-projector and read only by cmd/wes-reports
(ADR-0011).
Source: migrations/analytics/0001_report.up.sql,
internal/adapters/outbound/analyticsstore/migrate.go. No foreign keys.
schema_migrations_analytics is the bookkeeping table of the projector's own
migrator (CREATE TABLE IF NOT EXISTS in migrate.go), not a migration file.
Table ≠ aggregate
| Table | What it is | Owner in code |
|---|---|---|
charge_forecasts | Kept, no longer written (ADR-0049): the former ChargeForecast aggregate (buckets as JSONB) | — (no repository since ADR-0049) |
shift_plans | Kept, no longer written (ADR-0049): the former ShiftPlan aggregate, one row per path | — (no repository since ADR-0049) |
work_pools + work_pool_entries | WorkPool aggregate root + its entries | postgres.WorkPoolRepo (rewrites every entry on save, guarded by version; the work_pools row's mode / wip_limit are set by ConfigurePool, ADR-0034, or seeded ReleaseFed/1000 by the first enqueue) |
work_units | WorkUnit aggregate | postgres.WorkUnitRepo |
labor_plan_view | Read model LaborPlanObserved; its drift columns are deprecated read-backs, no longer computed (ADR-0049) | postgres.LaborPlanViewRepo |
usable_inventory_view | Read model UsableInventoryObserved | postgres.InventoryViewRepo |
product_classification_copy | Local copy of product-master's classification, read as ProductClassificationView (ADR-0035) | productclassificationcopy.Store |
slot_plans | Local record of slotting-optimization's approved plans this context applied or superseded (ADR-0040) | postgres.SlotPlanRepo |
product_pack_level_copy | Local copy of product-master's pack levels, keyed by GTIN (ADR-0045) | productclassificationcopy (pack store) |
processed_events | Infrastructure: consumer inbox / dedupe on CloudEvents id (ADR-0028) | postgres.ProcessedEventRepo |
outbox_events | Infrastructure: transactional outbox, one row per topic per event (ADR-0014); published rows swept after OUTBOX_RETENTION | postgres.OutboxPublisher, postgres.OutboxRelay |
idempotency_keys | Infrastructure: Idempotency-Key replay store (ADR-0022); swept after IDEMPOTENCY_KEY_TTL | RequireIdempotencyKey, postgres housekeeper |
events | Legacy, unused: created by 0001_init, no code reads or writes it. Decided 2026-10-06: retained, additive migrations only (never dropped without explicit approval) | — |
throughput_rollup | Analytics projection (not a source of truth) | analyticsstore.PostgresProjection / PostgresReport |
analytics_processed_events, analytics_consumed_events | Infrastructure: analytics idempotency layers | analyticsstore |
charge_forecasts and shift_plans (with the travel_distance_m /
travel_distance_estimated columns of migration 0010) are kept but no
longer written or read: the charge forecast and the shift plan moved to
warehouse-planning
(ADR-0049),
and dropping them waits for an explicit approval and its own migration.