Skip to main content

Entity-relationship diagram

Synced from product-master

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 OLTP schema after applying every migration in order. The OLTP Postgres database (DATABASE_URL) is migrated at boot by cmd/api with golang-migrate (postgres.RunMigrations, over MIGRATIONS_DATABASE_URL when set) from internal/adapters/outbound/postgres/migrations/. There are two migrations, 0001_products_outbox and 0002_product_pack_levels (ADR 0011). golang-migrate keeps its own schema_migrations table. DATABASE_URL is mandatory: there is no in-memory mode (ADR 0010). The separate analytical database (ANALYTICS_DATABASE_URL: tables analytics_processed_events, product_facts, profile_states, migrated by cmd/product-projector from analytics/migrations/) is described on the runbook and Runtime.

OLTP database​

Source: internal/adapters/outbound/postgres/migrations/0001_products_outbox.up.sql, 0002_product_pack_levels.up.sql (ADR 0011), internal/adapters/outbound/postgres/migrate.go, product_repository.go, outbox_repository.go, processed_event_repository.go. Omits: the indexes (idx_products_handling_tags, a GIN index for the handlingTag filter, and idx_outbox_events_unpublished, a partial index on unpublished rows). There are no foreign keys: the three tables are independent, so no relationship line is drawn. outbox_events.subject and key carry a SKU by value, not by reference.

Table is not aggregate​

TableBacksWritten byNotes
productsthe whole Product aggregate, flattened: classification and both halves of the physical profile are columns, not child tablesProductRepo.Save (insert when the loaded version is 0, else UPDATE ... WHERE sku = $1 AND version = <loaded>)One row per SKU; no history. The effective values, effectiveSource, discrepancy and volume are derived in Go, never stored.
outbox_eventsnothing in the domain: already-encoded Kafka messagesOutboxRepo.Insert in the use case's transaction; OutboxRepo.Drain marks rows publishedKept after publication (no cleanup job).
processed_eventsnothing in the domain: inbound-consumer idempotency claimsnobody today: ProcessedEventRepo.Claim (INSERT ... ON CONFLICT DO NOTHING, in the caller's transaction) was called only by the ADR 0003 legacy importer, removed at stage EKept by migration 0001 (no migration drops it); rows the importer claimed under consumer legacy-classification-importer remain.