Entity Relationship
The final schema after applying every migration in order. Part of the
DDD artifact pack. There are two databases:
the OLTP database (DATABASE_URL, migrations/0001–0010) and the
separate analytics database (ANALYTICS_DATABASE_URL,
migrations/analytics/0001), written only by pathmgmt-projector and
read only by pathmgmt-reports (ADR 0007). Both are migrated with
golang-migrate, which keeps its own schema_migrations table in each.
OLTP database
Source: migrations/0001_init.up.sql through
migrations/0010_process_flows.up.sql; schema_migrations is golang-migrate's
own table (internal/adapters/outbound/postgres/migrate.go). text_array
stands for Postgres TEXT[]. Omits: indexes
(idx_process_paths_active partial on status = 'ACTIVE',
idx_outbox_events_unpublished partial on published_at IS NULL,
idx_idempotency_keys_created_at) and the CHECK constraints on
status and destination_location_role.
The only FOREIGN KEYs in the schema are
cpt_schedule_cutoffs.schedule_site_id → cpt_schedules.site_id and
process_flow_stages.flow_id → process_flows.flow_id. Four
logical links deliberately have no foreign key:
process_flow_stages.path_id → process_paths.idis an aggregate boundary too: the path must be ACTIVE, which a foreign key cannot say, soDefineProcessFlowchecks it under the path's row lock (ADR 0042, ADR 0028).UNIQUE (flow_id, path_id)keeps a path to one stage per flow.cpt_schedule_cutoffs.eligible_path_ids → process_paths.idis an aggregate boundary. ADR 0010 checks it at write time in theDefineCPTScheduleuse case, "not by a foreign key", and it is stored as aTEXT[]that is never queried on its own.outbox_events.aggregate_idholds apath_id,site_idorflow_id(the Kafka key). The outbox is infrastructure and keeps rows independent of the aggregate tables; the sweeper deletes published rows after a retention period (ADR 0018).idempotency_keysstores a recorded HTTP response, not a reference to the path it created.
Analytics database
Source: migrations/analytics/0001_report.up.sql. Omits: the indexes on
occurred_at and day_bucket. There are no foreign keys: the two dedupe
tables hold CloudEvents ids, and the rollup is bucketed by UTC day.
Table ≠ aggregate
| Table | What it is | Aggregate / owner |
|---|---|---|
process_paths | Domain state | ProcessPath aggregate (one row per aggregate) |
cpt_schedules | Domain state | CPTSchedule aggregate root |
cpt_schedule_cutoffs | Domain state | Cutoff entities inside CPTSchedule; replaced wholesale on every CPTScheduleRepo.Save (delete then insert) |
process_flows | Domain state | ProcessFlow aggregate root (ADR 0042); version is the published event version |
process_flow_stages | Domain state | Stage values inside ProcessFlow; replaced wholesale on every ProcessFlowRepo.Save |
outbox_events | Infrastructure: transactional outbox (ADR 0003, topic column from ADR 0007) | One row per event per topic, written in the aggregate's transaction |
idempotency_keys | Infrastructure: Idempotency-Key replay cache (ADR 0011), swept by TTL (ADR 0018) | none — HTTP adapter |
schema_migrations | Infrastructure: golang-migrate bookkeeping | none |
analytics_processed_events | Analytics projection dedupe and freshness | pathmgmt-projector read model |
analytics_consumed_events | Analytics consumer dedupe gate, written in the same transaction as the projection (ADR 0032) | pathmgmt-projector read model |
catalogue_growth_rollup | Analytics projection, "Process Path Catalogue Growth & Change" | pathmgmt-projector read model, served by pathmgmt-reports |
There is no inbound processed_events table in the OLTP database: this
context consumes no other context's topic.