Skip to main content

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, and WorkPool.Reconcile heals a stale entry.
  • work_units.path_id, labor_plan_view.path_id (and the kept shift_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 its ProductClassified events (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 by ProductPackLevelDeclared / Retired / Measured events, 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​

TableWhat it isOwner in code
charge_forecastsKept, no longer written (ADR-0049): the former ChargeForecast aggregate (buckets as JSONB)— (no repository since ADR-0049)
shift_plansKept, no longer written (ADR-0049): the former ShiftPlan aggregate, one row per path— (no repository since ADR-0049)
work_pools + work_pool_entriesWorkPool aggregate root + its entriespostgres.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_unitsWorkUnit aggregatepostgres.WorkUnitRepo
labor_plan_viewRead model LaborPlanObserved; its drift columns are deprecated read-backs, no longer computed (ADR-0049)postgres.LaborPlanViewRepo
usable_inventory_viewRead model UsableInventoryObservedpostgres.InventoryViewRepo
product_classification_copyLocal copy of product-master's classification, read as ProductClassificationView (ADR-0035)productclassificationcopy.Store
slot_plansLocal record of slotting-optimization's approved plans this context applied or superseded (ADR-0040)postgres.SlotPlanRepo
product_pack_level_copyLocal copy of product-master's pack levels, keyed by GTIN (ADR-0045)productclassificationcopy (pack store)
processed_eventsInfrastructure: consumer inbox / dedupe on CloudEvents id (ADR-0028)postgres.ProcessedEventRepo
outbox_eventsInfrastructure: transactional outbox, one row per topic per event (ADR-0014); published rows swept after OUTBOX_RETENTIONpostgres.OutboxPublisher, postgres.OutboxRelay
idempotency_keysInfrastructure: Idempotency-Key replay store (ADR-0022); swept after IDEMPOTENCY_KEY_TTLRequireIdempotencyKey, postgres housekeeper
eventsLegacy, 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_rollupAnalytics projection (not a source of truth)analyticsstore.PostgresProjection / PostgresReport
analytics_processed_events, analytics_consumed_eventsInfrastructure: analytics idempotency layersanalyticsstore

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.