Phase 23: warehouse-service Postgres persistence (bonded_* tables) - #69
Merged
Merged
Conversation
…res (pgx v5), delete in-memory store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 23 fix C2 — warehouse-service Postgres persistence
servces/go/warehouse-service/cmd/main.gokept bonded warehouses, duty-suspension bonds, and inventory in a process-local map (var store); all data was lost on restart whileserver/routers/warehouse.tscalls it live.Change
pgxpool;DATABASE_URLenv required. Fail-closed: the servicelog.Fatals on missing/unreachable DB at startup and never falls back to memory. The in-memoryStoreis deleted.bonded_warehouses,bonded_inventory,ex_bond_permits) — no new migration,drizzle/untouched.GET /health,/api/warehouse/stats,/api/warehouse/list,/api/warehouse/inventory,POST /api/warehouse/register,/deposit,/release.license_no. Register is idempotent onlicense_noviaON CONFLICT (license_no) DO NOTHING.bonded_inventoryrow + incrementsused_cbmin one transaction. The 1:1 duty-suspension bond is carried by the inventory row (duty_liability_usd); bond id == inventory id.status='ex_bonded'/released_at+ decrementsused_cbm(GREATEST(...,0)) + inserts anex_bond_permitsrow (permit_no, duty_paid_usd, payment_ref, status 'used') — all in one transaction, mirroring the previous handler's bond-discharge logic.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).cmd/main_test.go: unused variable).Notes / residual risk
DATABASE_URLfor warehouse-service (service refuses to start without it — intended fail-closed).