Skip to main content

Entity-relationship diagram

The final schema after applying migrations/*.up.sql in order (0001_init → 0007_slot_version), and separately the analytics database (migrations/analytics/0001_report.up.sql). Both are applied by golang-migrate (internal/adapters/outbound/postgres/migrate.go), which also creates its own schema_migrations bookkeeping table in each database.

A relationship line is drawn only where a real FOREIGN KEY (REFERENCES) exists. Key markers: PK primary key, FK foreign key, UK part of a UNIQUE constraint, PK,FK both.

OLTP database (DATABASE_URL)​

Source: migrations/0001_init.up.sql … migrations/0007_slot_version.up.sql. Omitted: indexes (idx_zones_site_code, idx_aisles_zone_id, idx_location_slots_aisle_id, idx_location_slots_zone_id, idx_location_slots_grid, idx_location_slots_role, idx_fixed_structures_site_code, idx_cross_aisles_zone_id, idx_placement_rules_location_type, partial idx_outbox_events_unpublished, idx_idempotency_keys_created_at) and the events table that 0001 created and 0005 dropped. Postgres types are written with underscores (double_precision, text_array for TEXT[]) because Mermaid attribute types must be one word.

These are real references the code relies on, deliberately not enforced by a foreign key — each one is an aggregate boundary or an infrastructure concern:

FromToWhy no FK
cross_aisles.from_aisle, to_aisleaisles.aisle_code (within zone_id)They are aisle codes, not aisle ids; RegisterCrossAisle checks both belong to the zone (ErrCrossAisleAisleMismatch).
location_slots.site_segment … position_segmentsites / zones / aislesDenormalised LocationCode segments for the zone-grid query; the chain is enforced by RegisterLocationSlot.resolveChain and the zone_id / aisle_id FKs.
placement_rules.zone_code, temperature_class, hazmatzones columnsA predicate, not a reference: a rule matches any zone with those attributes.
outbox_eventsany aggregate tableOne row per encoded Kafka message; event_type and key name the source.
idempotency_keysany aggregate tableCached HTTP outcome keyed by the caller's Idempotency-Key.

Analytics database (ANALYTICS_DATABASE_URL)​

Written only by cmd/facility-projector, read only by cmd/facility-reports (ADR 0010). No foreign keys.

Source: migrations/analytics/0001_report.up.sql. Omitted: indexes idx_analytics_processed_events_occurred_at, idx_catalog_growth_rollup_day_bucket.

Table ≠ aggregate​

TableKindAggregate / ownerNotes
sitesaggregateSitetransfer capability + capability_revision (ADR-0035); version guard (migration 0008); site_role with a CHECK of the 16 values and a one-time backfill from the seeded names (migration 0009, ADR-0037); nullable capability_heartbeat_at = when the last capability heartbeat was raised (migration 0012, ADR-0041)
zonesaggregateZoneid = SITE-AREA-ZONE
aislesaggregateAisleid = ZoneID-AISLE; centreline columns are the Segment value object flattened
cross_aislesaggregateCrossAislecomposite natural key; status stored as a boolean
location_typesaggregateLocationTypecapacity columns are the Capacity value object flattened
placement_rulesaggregatePlacementRulepredicate columns are the ZonePredicate value object flattened
location_slotsaggregateLocationSlotLocationCode, Capacity, FunctionalAttributes, Point3D, Dimensions flattened into one row; the only versioned table
fixed_structuresaggregateFixedStructureRect flattened
outbox_eventsinfrastructuretransactional outbox (ADR 0018)published rows deleted after OUTBOX_RETENTION by the sweeper (ADR 0026)
idempotency_keysinfrastructureIdempotency-Key middleware (ADR 0019)deleted after IDEMPOTENCY_KEY_TTL by the sweeper
schema_migrationsinfrastructuregolang-migrateone per database
analytics_processed_eventsprojection infrastructureanalytics projectionclaimed in the same transaction as the rollup UPSERT
analytics_consumed_eventsprojection infrastructureanalytics consumer dedupe gate
catalog_growth_rollupprojectionLayout Catalog Growth and Change reportderived, rebuildable from the analytics topic

This repository has no processed_events inbox table in the OLTP database: the service consumes no other context's events.