Skip to main content

Entity-relationship diagram

Synced from warehouse-planning

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.

The final schemas after applying every migration in order. This service has two Postgres databases:

  • the OLTP database (DATABASE_URL), migrated by cmd/api and cmd/mcp from internal/adapters/outbound/postgres/migrations/0001 to 0015;
  • the separate analytical database (ANALYTICS_DATABASE_URL, warehouse_planning_analytics), migrated and written only by cmd/planning-projector from analytics/migrations/0001 (ADR 0005).

Both are migrated with golang-migrate (postgres.RunMigrations), which keeps its own schema_migrations table in each database. There is no top-level migrations/ directory in this repository.

OLTP database​

Source: internal/adapters/outbound/postgres/migrations/0001_process_capacity.up.sql through 0017_capacity_plan_superseded.up.sql, 0018_process_flows.up.sql (the process_flows copy of ADR 0025) and 0019_drop_process_paths.up.sql (the local table gone, stage 3), internal/adapters/outbound/postgres/migrate.go. Omits: the indexes (idx_capacity_plans_warehouse_window, idx_outbox_events_unpublished partial on published_at IS NULL, idx_order_demand_location_promise, idx_inbound_appointments_location_window partial on status = 'BOOKED', idx_labor_standards_task_site_effective partial on handling_unit = '') and column defaults. Types are drawn in lower case with _ instead of spaces (double_precision, text_array for TEXT[]) because Mermaid types cannot contain spaces or brackets.

The only foreign key in the schema is process_capacity_constraint (process_type, location, window_start, window_end) referencing process_capacity, with ON DELETE CASCADE. Every other link is logical and deliberately has no foreign key:

  • capacity_plans.process_path_id names an ACTIVE process_flows.flow_id, but a plan stores its computed result and must survive the flow being revised or retired; the two are different aggregates.
  • capacity_plans.location and the step process_types line up with process_capacity rows only through window coverage at creation time; the plan never reads them again.
  • station_standards (location, process_type) and location_slot_tally (zone ids starting with <location>-, tally_key = activity) are joined by a string prefix at read time (ADR 0002), not by a key.
  • location_slot_registration.(zone_id, tally_type, tally_keys) remembers which location_slot_tally buckets a slot incremented, so a decommission knows what to decrement.
  • outbox_events.subject and key are the raising aggregate's id: the capacity plan id, the ProcessCapacity identity, <site_id>/<path_id> for a workload forecast, <site_id>/<shift_id>/<path_id> for a labour plan and its drift.
  • processed_events.event_id is the CloudEvents id of a consumed message; consumer is labor-capacity-consumer, storage-capacity-consumer, order-demand-consumer, dock-appointment-consumer (it was inbound-demand-consumer), observed-capacity-consumer or labor-standard-consumer.
  • The three requirement-side tables of ADR 0023 share the key (site_id, [shift_id,] path_id) but have no foreign key between them: labour_plans reads workload_forecasts only when heads are derived (and keeps the number, not a reference), and labour_plan_commitments may hold a key no plan has yet (a commitment that arrived first) or a plan may have no commitment. Site and shift match exactly as sent; path_id is stored in its canonical form (trimmed, upper case) in all three tables, like the LABOR constraint's ProcessType.
  • labor_standards holds facts, not a current value: the standard a plan uses is resolved at read time; capacity_plans.labour_requirement stores the result, so a later revision never rewrites a stored plan (ADR 0022).
  • inbound_appointments.appointment_id names dock-scheduling's appointment (ADR 0017, source switched by ADR 0020); location is the site_id of its events. Rows written under the retired inbound-receiving source are INBOUND at version 0 and keep the site they were stored under until dock-scheduling next writes the appointment. inbound_labour_standards.process_path_id names a process_paths.id but is operator-declared and never defaulted, so it has no key. observed_capacity is fed by fulfillment-execution's TaskCompleted events and is advisory input only (ADR 0017); none of the three new tables has a foreign key.

Analytical database​

Source: analytics/migrations/0001_plan_facts.up.sql, internal/adapters/outbound/analyticsstore/postgres_projection.go. Omits: the partial indexes idx_plan_facts_published_at and idx_plan_facts_created_at. There is no foreign key: plan_facts.plan_id is a capacity plan id from the other database, and analytics_processed_events.event_id is the CloudEvents id applied in the same transaction as the plan_facts upsert.

Table is not aggregate​

TableRoleAggregate / model
process_capacity + process_capacity_constraintAggregate state (parent + child rows)ProcessCapacity aggregate
capacity_plansAggregate stateCapacityPlan aggregate
process_flowsEvent-fed copy of process-path-management's flows (ADR 0025; the process_paths table dropped with 0019)processflow.Flow
station_standardsStored value objectsprocesscapacity.StationStandard
location_slot_tally, location_slot_registrationRead model of facility-layout eventsfacility tally (internal/application/tally)
order_demandRead model of order-management eventsdemand.Order
inbound_appointmentsRead model of dock-scheduling's dock appointments (ADR 0017, ADR 0020)inbound labour demand (internal/application)
inbound_labour_standardsOperator-declared labour standard per site and path (ADR 0017)none (read at plan creation)
observed_capacityRead model of fulfillment-execution's completed tasks (ADR 0017)none (advisory variance input)
labor_standardsLocal copy of labor-performance's engineered standards (ADR 0022)laborstandard.Standard (resolved at read time)
workload_forecastsAggregate state (ADR 0023)WorkloadForecast aggregate
labour_plansAggregate state (ADR 0023)LabourPlan aggregate
labour_plan_commitmentsRead model of workforce-management's committed heads, plus the last recorded drift (ADR 0023 decision 3)labourplan.Commitment
processed_eventsInfrastructure: consumer idempotency claimsnone
outbox_eventsInfrastructure: transactional outbox (two rows per domain event since 0007)none
schema_migrationsInfrastructure: golang-migrate bookkeepingnone
plan_factsAnalytics projection (separate database)none (derived from the analytics stream)
analytics_processed_eventsInfrastructure / analytics: projector idempotencynone

The idempotency_keys table (migration 0011_idempotency_keys, ADR 0019) holds the fleet Idempotency-Key answers of the four REST POSTs; the key row commits in the same unit of work as the aggregate change and the outbox rows.