feat: normalize payout milestones (#110) - #130
Open
kimanicode wants to merge 1 commit into
Open
Conversation
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.
Summary
closes #110: normalizes payout milestones out of a JSON blob on
Payout.milestonesinto propermilestones,milestone_evidence, andmilestone_historycollections, with a zero-downtime expand/backfill/verify migration.Note: the issue text references
prisma/schema.prisma,useMilestoneActions.ts, andManageMilestonesDialog.tsx- none of these exist in this repo (it's MongoDB-based, no Prisma). This PR implements the real equivalents under their actual names/extensions (schemaContracts.js,useMilestoneActions.js,ManageMilestonesDialog.jsx).What changed
Schema / migration
schemaContracts.js- addedmilestones,milestone_evidence,milestone_historytoCOLLECTIONS, added indexes and validators for all three, and kept the legacymilestonesarray onpayoutsfor backward compatibility during rolloutmigrations/005-normalize-payout-milestones.js- expand/backfill/verify migration with adown()to drop the new collections/indexes if needed. Handles null, empty, legacy-shaped, and malformed milestone payloads explicitly, with an exception report rather than silent skippingmigrations/registry.jsService layer
milestoneService.js- dual-read (normalized model, falls back to legacy JSON), dual-write (writes the new model and keepspayout.milestonesin sync during rollout), optimistic concurrency via a version field, and evidence/history CRUDAPI routes (none of these existed before this PR -
useEscrow.jsalready referenced/api/escrows/:id/milestones, but the route itself was missing)GET/POST /api/escrows/[escrowId]/milestonesGET/PUT/DELETE /api/milestones/[milestoneId](PUTuses optimistic concurrency)POST /api/milestones/[milestoneId]/submitPOST /api/milestones/[milestoneId]/approvePOST /api/milestones/[milestoneId]/rejectGET/POST /api/milestones/[milestoneId]/evidenceFrontend
hooks/useMilestoneActions.js- mutation hooks for create/update/submit/approve/reject/addEvidencecomponents/milestones/ManageMilestonesDialog.jsx- milestone management modalDocs
docs/payout-milestone-migration-runbook.md- expand/backfill/verify runbook, including rollback procedure and the contract-phase planUnrelated fix included
Found and fixed a pre-existing syntax bug in
schemaContracts.js: theupload_quarantineentry inREQUIRED_INDEXESwas missing a closing],. Small, low-risk, but genuinely unrelated to milestones - flagging so it's not confused with in-scope work during review.Concurrency safety
Milestone updates now go through targeted, per-document operations with an optimistic-concurrency version check, instead of whole-blob read-modify-write on
Payout.milestones- concurrent updates to different milestones on the same payout can no longer clobber each other.Tests
tests/backend/payout-milestone-migration.test.mjs- 19 tests: payload handling (empty/null/legacy/malformed), idempotency, and verification-mismatch detectiontests/backend/milestone-api-routes.test.mjs- 12 integration tests coveringmilestoneServicereads, transitions, and evidencetests/backend/helpers/fakeMongo.mjswith.sort(),$push, and.aggregate()support, needed by the new service/testsAcceptance criteria