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_linesandorder_groupsare theCustomerOrderaggregate, saved together under the optimistic rule "storedversionequals the version loaded".shoppersandshopper_addressesare theShopperaggregate;shopper_addressesreplaced the old JSON column in migration 0003 (legacy addresses got idslegacy-<md5>). - PII.
customer_orders.ship_toandshopper_addressesare the only places an address is stored. The order list indexcustomer_orders_history_idx (shopper_id, placed_at DESC, order_id)servesGET /orders?shopperId=keyset paging. - Read model.
group_signals,tracking_packages,tracking_package_groupsandassignment_linksare event-fed upserts that tolerate any arrival order; they are joined with the order's groups byGET /orders/{orderId}/tracking. - Infrastructure.
processed_events(inbox) is written in the same transaction as the effect it guards.idempotency_keysholds a POST answer for 24 hours.outbox_eventshas a partial index on rows not yet published; the relay claims them, and rows pastOUTBOX_MAX_ATTEMPTSfailures 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 indexcompensation_cancels_pending_idxon rows withreleased_at IS NULL), setsreleased_atwhen the cancel succeeds (or delivery-promise refuses it because the promise is already closed), and recordsattemptsandlast_erroron a failure. Rows pastCOMPENSATION_MAX_ATTEMPTSfailures 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_URLis the direct DSN,DATABASE_URLgoes through PgBouncer).