Skip to content

Migrate Float monetary fields to Decimal in Prisma schema #237

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

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