Entity-relationship diagrams
Labor Performance owns two Postgres databases (ADR 0007): the OLTP
database written by cmd/labor (migrations in migrations/, applied by
golang-migrate at boot of cmd/labor and cmd/mcp), and the analytical
database written only by cmd/labor-projector and read through a
read-only pool by cmd/labor-reports (migrations in
migrations/analytics/). Both diagrams show the final schema after
every *.up.sql is applied in order.
Not one table in either database declares a FOREIGN KEY, so neither
diagram draws a relationship line. The logical links that do exist are
explained in prose under each diagram — they are aggregate boundaries or
copied values, deliberately not enforced by the database.
OLTP database
Source: migrations/0001_init.up.sql, migrations/0002_outbox.up.sql,
migrations/0003_idle_periods.up.sql,
migrations/0004_travel_component_seconds.up.sql,
migrations/0005_idempotency_keys.up.sql,
migrations/0006_standard_version_and_one_open.up.sql,
migrations/0007_handling_unit_standards.up.sql,
migrations/0008_standard_site_scope.up.sql;
schema_migrations is golang-migrate's own bookkeeping table
(internal/adapters/outbound/postgres/migrate.go). Omitted: index names
(listed below) and the .down.sql files.
Indexes: idx_labor_standards_task_type,
idx_labor_standards_one_open_per_task_type (UNIQUE on task_type
WHERE effective_to IS NULL, ADR 0022; widened to
(task_type, handling_unit) by ADR 0035 and to (task_type,
handling_unit, site_code) by ADR 0038),
idx_task_performances_associate_id, idx_task_performances_task_type,
idx_idle_periods_associate_id_ended_at,
idx_idle_periods_task_type_ended_at, idx_outbox_events_unpublished
(id WHERE published_at IS NULL), idx_idempotency_keys_created_at.
DOUBLE_PRECISION is written with an underscore only because Mermaid
attribute types cannot contain a space.
Logical links without a foreign key
task_performances.standard_seconds_at_completionis a copy of thelabor_standards.expected_secondsthat was active as ofcompleted_at(ADR 0004). There is deliberately nostandard_idcolumn: a later revision must never change a scored row.task_performances.event_idandprocessed_events.event_idhold the same CloudEventsid; both are written in the same transaction byRecordTaskPerformance, butprocessed_eventsis the idempotency gate and could in principle hold ids for events that produced no row.idle_periods.associate_id/task_typematch thetask_performancesrow recorded in the same transaction, but there is no link column — anIdlePeriodis its own aggregate.task_id,associate_idandtask_typeare foreign references intofulfillment-execution's model; this context does not own or validate them.
Analytical database
Source: migrations/analytics/0001_report.up.sql,
internal/adapters/outbound/analyticsstore/postgres_projection.go,
internal/adapters/outbound/analyticsstore/consumed_events_repo.go.
Omitted: index names (idx_labor_performance_rollup_hour_bucket,
idx_analytics_processed_events_occurred_at).
Logical links without a foreign key
analytics_consumed_events(the consumer's dedupe gate) andanalytics_processed_events(the projection's claim, also the source of freshness lag) hold the same CloudEvents ids fromwarehouse.labor-performance.analytics. They are kept as separate tables so the two idempotency layers never race for one row.- The rollup stores only raw counters and sums; every mean is derived at
read time by
report.mean, so an hour with no scored tasks has a null mean, never0.
Table ≠ aggregate
| Table | Database | What it is | Aggregate / model |
|---|---|---|---|
labor_standards | OLTP | Aggregate state (append-only history) | standard.LaborStandard |
task_performances | OLTP | Aggregate state; also the source of every OLTP read model | performance.TaskPerformance; read by Scorecard, TaskTypePerformance, UtilizationResult |
idle_periods | OLTP | Aggregate state | idleness.IdlePeriod |
processed_events | OLTP | Infrastructure — inbox / idempotency gate for consumed TaskCompleted | ports.ProcessedEvents |
outbox_events | OLTP | Infrastructure — transactional outbox (ADR 0010), swept 7 days after publish (ADR 0023) | postgres.OutboxPublisher, postgres.OutboxRelay |
idempotency_keys | OLTP | Infrastructure — HTTP Idempotency-Key store for POST /standards (ADR 0016), swept after 24 h | http.RequireIdempotencyKey |
schema_migrations | both | Infrastructure — golang-migrate bookkeeping | — |
labor_performance_rollup | analytics | Projection — rebuildable from the analytics topic | report.Row → report.LaborPerformanceReport |
analytics_processed_events | analytics | Projection infrastructure — projection claim + freshness | analyticsstore.PostgresProjection |
analytics_consumed_events | analytics | Projection infrastructure — consumer dedupe gate | analyticsstore.ConsumedEventsRepo |