Skip to content

Migrate Float monetary fields to Decimal in Prisma schema #237

Closed

Description

@kilodesodiq-arch

Problem Statement. Money is stored as Float in Campaign.budget, Claim.amount,
AidPackage.totalAmount/claimedAmount/remainingAmount, and BalanceLedger.amount. Doubles
cannot 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.30000000000000004 and proceed to disburse incorrectly.

Technical Context. prisma/schema.prisma. Decimal is supported by Prisma + Postgres
natively; for SQLite the round-trip goes via string.

Expected Outcome. All monetary fields use Decimal with String representation for
the JS client. Existing data is migrated in a single script using BigInt arithmetic.

Acceptance Criteria.

  • New schema field types: Decimal @db.Decimal(38, 18).
  • A migration script prisma/migrations/<ts>_floats_to_decimal/migration.sql covers the
    four models.
  • A unit-test in app/backend/test/money-roundtrip.spec.ts proves
    Decimal("1000.5") round-trips losslessly through Python, JS, and Postgres client.
  • API responses explicitly serialize decimals as strings (use a custom DecimalSerializerInterceptor).

Implementation Notes. Avoid parseFloat anywhere in the consumer code; use Decimal 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.

Activity

  1. DeRossa1 commented on Jul 21, 2026

    @DeRossa1
    Contributor

    I can resolve this issue, assign me.

  2. grantfox-oss commented on Jul 21, 2026

    @grantfox-oss

    🦊 GrantFox — @DeRossa1 has been assigned to this issue as part of the Official Campaign | FWC26 campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #237)
    2. Your PR will be reviewed by the ChainForgee maintainers

    Good luck! Track your progress on GrantFox.

  3. grantfox-oss commented on Jul 22, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox as part of the Official Campaign | FWC26 campaign!

    @DeRossa1's PR #410 was approved and merged by @kilodesodiq-arch.

    🏆 @DeRossa1: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (83 total points). Track your full progress on GrantFox.

    👏 Great work, @DeRossa1! Keep contributing to ChainForgee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions