Skip to main content

Entity-relationship diagram

The Postgres schema as the embedded migrations create it (internal/adapters/outbound/postgres/migrations/0001 to 0011, applied at boot by golang-migrate). Thirteen tables of the context plus golang-migrate's own schema_migrations. Foreign keys exist only where the diagram draws a relationship; the tracking read model and the infrastructure tables are keyed by ids copied from events and carry no foreign key.

Source: internal/adapters/outbound/postgres/migrations/0001_customer_ordering_schema.up.sql, 0002_package_lost_and_returned.up.sql, 0003_shopper_addresses_and_order_history.up.sql, 0004_group_window_time_zone.up.sql, 0005_compensation_cancels.up.sql, 0006_order_consolidation_key.up.sql (adds customer_orders.consolidation_key), 0007_tracking_package_groups.up.sql, 0008_group_consolidated_choice.up.sql (the CONSOLIDATED tier and the shopper's choice on order_groups), 0009_tracking_package_eta.up.sql, 0010_tracking_package_point_flag.up.sql, 0011_order_pickup_destination.up.sql (the pickup destination of an order and the collection columns of tracking_packages). Columns not drawn: order_groups also holds node_id, locked_at, shipped_at, delivered_at, cancel_requested_at, cancelled_at, cancel_refused_reason, lost_at, returned_at; tracking_packages also holds last_scan_node_id, outcome_at, and keeps order_id/group_no as "the first group that named the package" (ADR 0012: the set of groups of a package is tracking_package_groups, rows only added, so merged groups can share one tracking number); outbox_events also holds subject, dataschema, created_at.

Reading it​

  • Aggregates. customer_orders, order_lines and order_groups are the CustomerOrder aggregate, saved together under the optimistic rule "stored version equals the version loaded". shoppers and shopper_addresses are the Shopper aggregate; shopper_addresses replaced the old JSON column in migration 0003 (legacy addresses got ids legacy-<md5>).
  • PII. customer_orders.ship_to and shopper_addresses are the only places an address is stored. The order list index customer_orders_history_idx (shopper_id, placed_at DESC, order_id) serves GET /orders?shopperId= keyset paging.
  • Read model. group_signals, tracking_packages, tracking_package_groups and assignment_links are event-fed upserts that tolerate any arrival order; they are joined with the order's groups by GET /orders/{orderId}/tracking.
  • Infrastructure. processed_events (inbox) is written in the same transaction as the effect it guards. idempotency_keys holds a POST answer for 24 hours. outbox_events has a partial index on rows not yet published; the relay claims them, and rows past OUTBOX_MAX_ATTEMPTS failures are excluded from claims (see the Runbook).
  • Compensation queue. compensation_cancels (migration 0005) is the durable queue of promise cancels that a failed checkout could not perform at delivery-promise. A row is unique per (order_id, group_no, promise_id); the compensation worker claims unreleased rows in id order (partial index compensation_cancels_pending_idx on rows with released_at IS NULL), sets released_at when the cancel succeeds (or delivery-promise refuses it because the promise is already closed), and records attempts and last_error on a failure. Rows past COMPENSATION_MAX_ATTEMPTS failures are excluded from claims (see the Runbook). Like the infrastructure tables it carries no foreign key.
  • Down migrations exist for all eleven steps; there is no cross-service database access (MIGRATIONS_DATABASE_URL is the direct DSN, DATABASE_URL goes through PgBouncer).