Skip to main content

Entity relationship

One PostgreSQL schema, created by migrations/0001_outbound_shipping_schema.up.sql (embedded in the binaries, applied at boot). There are no foreign keys: aggregates reference each other by id and the local copies are joined in Go or by key. The relationships drawn below are logical.

Source: migrations/0001_outbound_shipping_schema.up.sql, internal/adapters/outbound/postgres/*.go.

Some columns are omitted for readability (created_at/updated_at, dataschema, key, content_type, window_start, window_end, booked_at, void_reason). The migration has the full list.

Tables​

TableRoleKey and constraintsWritten by
outbound_loadsOutboundLoad aggregatePK load_id; state check (5 values); version >= 1; partial unique index uq_open_load_per_cutoff on (site_id, cpt_id, operating_date, ship_method) where state IN ('PLANNED','LOADING'); indexes for listing, site and state, open loads by site and cpt, open loads by site and door, loads by site and trailerExpectPackage, door, dock, close, reopen, cancel, confirm
shipping_packagesShippingPackage aggregatePK package_id; state check (5 values); weight_g >= 0; indexes by load, by load and state, listing, site and missedExpectPackage, scans, close, confirm, sweep
bills_of_ladingBillOfLading aggregatePK bol_number; UNIQUE (load_id) (one document per load); package_count >= 1; state checkOnDeparture, VoidBillOfLading
cpt_scheduleslocal copy of the cutoff schedulePK site_id; the whole schedule replaced per eventcpt consumer
zones, locationslocal copy of staging locationsPK zone_id, location_code; a location's site is its zone's site; empty role means Storagelayout consumer
dock_appointmentslocal copy of appointments acted onPK appointment_id; carrier and SCAC read back at ship-confirmdock consumer
door_work_completionscopy of DoorWorkCompletedPK (trailer_id, completed_at)yard consumer
load_boardLoadBoardView projectionPK load_id; index (site_id, operating_date, cpt_id) for the reportanalytics consumer
outbox_eventstransactional outboxPK id; UNIQUE (event_id, topic); partial index of unpublished rowsuse cases (insert), relay (drain)
processed_eventsinboxPK (consumer, event_id)every consumer
idempotency_keysstored answers of REST POSTsPK key; status between 200 and 499; index on created_atthe Idempotency-Key middleware

Text keys that are compared or ordered in Go use the "C" collation so ordering and keyset comparisons follow byte order. The migration has a .down.sql; there is no other migration.

There is no analytics database and no retention job: outbox_events, processed_events and idempotency_keys grow without a purge (see the runbook).