Skip to main content

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.id is an aggregate boundary too: the path must be ACTIVE, which a foreign key cannot say, so DefineProcessFlow checks 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.id is an aggregate boundary. ADR 0010 checks it at write time in the DefineCPTSchedule use case, "not by a foreign key", and it is stored as a TEXT[] that is never queried on its own.
  • outbox_events.aggregate_id holds a path_id, site_id or flow_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_keys stores 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​

TableWhat it isAggregate / owner
process_pathsDomain stateProcessPath aggregate (one row per aggregate)
cpt_schedulesDomain stateCPTSchedule aggregate root
cpt_schedule_cutoffsDomain stateCutoff entities inside CPTSchedule; replaced wholesale on every CPTScheduleRepo.Save (delete then insert)
process_flowsDomain stateProcessFlow aggregate root (ADR 0042); version is the published event version
process_flow_stagesDomain stateStage values inside ProcessFlow; replaced wholesale on every ProcessFlowRepo.Save
outbox_eventsInfrastructure: transactional outbox (ADR 0003, topic column from ADR 0007)One row per event per topic, written in the aggregate's transaction
idempotency_keysInfrastructure: Idempotency-Key replay cache (ADR 0011), swept by TTL (ADR 0018)none — HTTP adapter
schema_migrationsInfrastructure: golang-migrate bookkeepingnone
analytics_processed_eventsAnalytics projection dedupe and freshnesspathmgmt-projector read model
analytics_consumed_eventsAnalytics consumer dedupe gate, written in the same transaction as the projection (ADR 0032)pathmgmt-projector read model
catalogue_growth_rollupAnalytics 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.