Skip to content

Phase 23: warehouse-service Postgres persistence (bonded_* tables) - #69

Merged
munisp merged 5 commits into
mainfrom
phase23/warehouse-persistence
Oct 2, 2026
Merged

munisp merged 5 commits into
mainfrom
phase23/warehouse-persistence

Conversation

@munisp

@munisp munisp commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Phase 23 fix C2 — warehouse-service Postgres persistence

servces/go/warehouse-service/cmd/main.go kept bonded warehouses, duty-suspension bonds, and inventory in a process-local map (var store); all data was lost on restart while server/routers/warehouse.ts calls it live.

Change

  • pgx v5 (v5.9.2) with pgxpool; DATABASE_URL env required. Fail-closed: the service log.Fatals on missing/unreachable DB at startup and never falls back to memory. The in-memory Store is deleted.
  • Persists to the existing Drizzle-managed tables (bonded_warehouses, bonded_inventory, ex_bond_permits) — no new migration, drizzle/ untouched.
  • All routes and JSON response shapes unchanged: GET /health, /api/warehouse/stats, /api/warehouse/list, /api/warehouse/inventory, POST /api/warehouse/register, /deposit, /release.
  • ID semantics: serial ids are returned as strings; handlers accept numeric ids or license_no. Register is idempotent on license_no via ON CONFLICT (license_no) DO NOTHING.
  • deposit: inserts bonded_inventory row + increments used_cbm in one transaction. The 1:1 duty-suspension bond is carried by the inventory row (duty_liability_usd); bond id == inventory id.
  • release: sets status='ex_bonded'/released_at + decrements used_cbm (GREATEST(...,0)) + inserts an ex_bond_permits row (permit_no, duty_paid_usd, payment_ref, status 'used') — all in one transaction, mirroring the previous handler's bond-discharge logic.
  • /health runs a real SELECT 1 (db:"ok", 503 when unreachable) and reports live table counts.

Verification

  • go build ./..., go vet ./..., go test ./... all pass (Go 1.25.4).
  • Also fixed a pre-existing test compile error (cmd/main_test.go: unused variable).

Notes / residual risk

  • Table columns are integer cbm/kg/USD; float inputs are rounded (documented in code).
  • Deployment must set DATABASE_URL for warehouse-service (service refuses to start without it — intended fail-closed).

@munisp
munisp merged commit 431e42c into main Oct 2, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant