Skip to main content

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.

No foreign keys

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_completion is a copy of the labor_standards.expected_seconds that was active as of completed_at (ADR 0004). There is deliberately no standard_id column: a later revision must never change a scored row.
  • task_performances.event_id and processed_events.event_id hold the same CloudEvents id; both are written in the same transaction by RecordTaskPerformance, but processed_events is the idempotency gate and could in principle hold ids for events that produced no row.
  • idle_periods.associate_id / task_type match the task_performances row recorded in the same transaction, but there is no link column — an IdlePeriod is its own aggregate.
  • task_id, associate_id and task_type are foreign references into fulfillment-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) and analytics_processed_events (the projection's claim, also the source of freshness lag) hold the same CloudEvents ids from warehouse.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, never 0.

Table ≠ aggregate​

TableDatabaseWhat it isAggregate / model
labor_standardsOLTPAggregate state (append-only history)standard.LaborStandard
task_performancesOLTPAggregate state; also the source of every OLTP read modelperformance.TaskPerformance; read by Scorecard, TaskTypePerformance, UtilizationResult
idle_periodsOLTPAggregate stateidleness.IdlePeriod
processed_eventsOLTPInfrastructure — inbox / idempotency gate for consumed TaskCompletedports.ProcessedEvents
outbox_eventsOLTPInfrastructure — transactional outbox (ADR 0010), swept 7 days after publish (ADR 0023)postgres.OutboxPublisher, postgres.OutboxRelay
idempotency_keysOLTPInfrastructure — HTTP Idempotency-Key store for POST /standards (ADR 0016), swept after 24 hhttp.RequireIdempotencyKey
schema_migrationsbothInfrastructure — golang-migrate bookkeeping—
labor_performance_rollupanalyticsProjection — rebuildable from the analytics topicreport.Row → report.LaborPerformanceReport
analytics_processed_eventsanalyticsProjection infrastructure — projection claim + freshnessanalyticsstore.PostgresProjection
analytics_consumed_eventsanalyticsProjection infrastructure — consumer dedupe gateanalyticsstore.ConsumedEventsRepo