-
Notifications
You must be signed in to change notification settings - Fork 84
Migrate Float monetary fields to Decimal in Prisma schema #237
Copy link
Copy link
Closed
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Campaign: Official Campaign | FWC26area:backendBackend (NestJS) areaBackend (NestJS) areakind:performancePerformance / scalabilityPerformance / scalabilitykind:refactorRefactor / cleanupRefactor / cleanup
Description
Activity
Metadata
Metadata
Assignees
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Campaign: Official Campaign | FWC26area:backendBackend (NestJS) areaBackend (NestJS) areakind:performancePerformance / scalabilityPerformance / scalabilitykind:refactorRefactor / cleanupRefactor / cleanup
Problem Statement. Money is stored as
FloatinCampaign.budget,Claim.amount,AidPackage.totalAmount/claimedAmount/remainingAmount, andBalanceLedger.amount. Doublescannot represent one USDC cent exactly and SQLite further mangles them.
Why it matters. Floats in money-handling systems are a class of bug. The schema is
the cross-language boundary; a Swift or Go client that reads these values can pick up
0.1 + 0.2 == 0.30000000000000004and proceed to disburse incorrectly.Technical Context.
prisma/schema.prisma.Decimalis supported by Prisma + Postgresnatively; for SQLite the round-trip goes via string.
Expected Outcome. All monetary fields use
DecimalwithStringrepresentation forthe JS client. Existing data is migrated in a single script using
BigIntarithmetic.Acceptance Criteria.
Decimal @db.Decimal(38, 18).prisma/migrations/<ts>_floats_to_decimal/migration.sqlcovers thefour models.
app/backend/test/money-roundtrip.spec.tsprovesDecimal("1000.5")round-trips losslessly through Python, JS, and Postgres client.DecimalSerializerInterceptor).Implementation Notes. Avoid
parseFloatanywhere in the consumer code; useDecimal js.Files or modules likely to be affected.
prisma/schema.prisma,prisma/migrations/*,src/common/decimal.ts(new),src/main.ts.Dependencies. #30 (data migration tooling).
Difficulty. Hard
Estimated effort. L
Backlog item #29 from `docs/maintainer-issue-backlog.md.