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.
The final schemas after applying every migration in order. This service has two Postgres databases:
- the OLTP database (
DATABASE_URL), migrated bycmd/apiandcmd/mcpfrominternal/adapters/outbound/postgres/migrations/0001to0015; - the separate analytical database (
ANALYTICS_DATABASE_URL,warehouse_planning_analytics), migrated and written only bycmd/planning-projectorfromanalytics/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_idnames an ACTIVEprocess_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.locationand the stepprocess_types line up withprocess_capacityrows only through window coverage at creation time; the plan never reads them again.station_standards (location, process_type)andlocation_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 whichlocation_slot_tallybuckets a slot incremented, so a decommission knows what to decrement.outbox_events.subjectandkeyare 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_idis the CloudEvents id of a consumed message;consumerislabor-capacity-consumer,storage-capacity-consumer,order-demand-consumer,dock-appointment-consumer(it wasinbound-demand-consumer),observed-capacity-consumerorlabor-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_plansreadsworkload_forecastsonly when heads are derived (and keeps the number, not a reference), andlabour_plan_commitmentsmay 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_idis stored in its canonical form (trimmed, upper case) in all three tables, like the LABOR constraint'sProcessType. labor_standardsholds facts, not a current value: the standard a plan uses is resolved at read time;capacity_plans.labour_requirementstores the result, so a later revision never rewrites a stored plan (ADR 0022).inbound_appointments.appointment_idnames dock-scheduling's appointment (ADR 0017, source switched by ADR 0020);locationis thesite_idof 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_idnames aprocess_paths.idbut is operator-declared and never defaulted, so it has no key.observed_capacityis fed by fulfillment-execution'sTaskCompletedevents 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
| Table | Role | Aggregate / model |
|---|---|---|
process_capacity + process_capacity_constraint | Aggregate state (parent + child rows) | ProcessCapacity aggregate |
capacity_plans | Aggregate state | CapacityPlan aggregate |
process_flows | Event-fed copy of process-path-management's flows (ADR 0025; the process_paths table dropped with 0019) | processflow.Flow |
station_standards | Stored value objects | processcapacity.StationStandard |
location_slot_tally, location_slot_registration | Read model of facility-layout events | facility tally (internal/application/tally) |
order_demand | Read model of order-management events | demand.Order |
inbound_appointments | Read model of dock-scheduling's dock appointments (ADR 0017, ADR 0020) | inbound labour demand (internal/application) |
inbound_labour_standards | Operator-declared labour standard per site and path (ADR 0017) | none (read at plan creation) |
observed_capacity | Read model of fulfillment-execution's completed tasks (ADR 0017) | none (advisory variance input) |
labor_standards | Local copy of labor-performance's engineered standards (ADR 0022) | laborstandard.Standard (resolved at read time) |
workload_forecasts | Aggregate state (ADR 0023) | WorkloadForecast aggregate |
labour_plans | Aggregate state (ADR 0023) | LabourPlan aggregate |
labour_plan_commitments | Read model of workforce-management's committed heads, plus the last recorded drift (ADR 0023 decision 3) | labourplan.Commitment |
processed_events | Infrastructure: consumer idempotency claims | none |
outbox_events | Infrastructure: transactional outbox (two rows per domain event since 0007) | none |
schema_migrations | Infrastructure: golang-migrate bookkeeping | none |
plan_facts | Analytics projection (separate database) | none (derived from the analytics stream) |
analytics_processed_events | Infrastructure / analytics: projector idempotency | none |
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.