feat: migrate BalanceLedger.amount from Float to Decimal with running totals (#261) - #325
Open
DevSolex wants to merge 3 commits into
Open
Conversation
Contributor
|
Hi 👋 Appreciate this PR! The CI is flagging a failing check — could you take a peek at the failed job and push a fix? Happy to help if you need a hand 🙏 |
…napshot (ChainForgee#261) - Change BalanceLedger.amount from Float to Decimal(20,8) in schema - Add BalanceLedgerSnapshot model with totalLocked Decimal and snapshotAt - Migration 20260715000000_balance_ledger_decimal_and_snapshot recreates the BalanceLedger table with DECIMAL column and creates the snapshot table - Add BalanceLedgerSnapshotJob (hourly cron) that computes Σ amount for the last 24 h per campaign and writes a BalanceLedgerSnapshot row - Register job in JobsModule - Fix BudgetService._sum.amount handling for Decimal return type - Fix CampaignsService balanceLedger.reduce to call toNumber() on Decimal - Add unit spec (balance-ledger-snapshot.job.spec.ts) – 3 tests pass - Add e2e spec (balance-ledger-snapshot.e2e-spec.ts) asserting running total matches Σ BalanceLedger.amount for the last 24 h Closes ChainForgee#261
DevSolex
force-pushed
the
feat/261-balance-ledger-decimal-running-totals
branch
from
July 24, 2026 17:21
d7a83e3 to
8fd7f66
Compare
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
Implements issue #261.
Migrates
BalanceLedger.amountfromFloattoDecimal(20,8)and adds a denormalisedBalanceLedgerSnapshottable populated by a scheduled hourly job.Changes
Schema (
prisma/schema.prisma)BalanceLedger.amount:Float→Decimal @db.Decimal(20,8)BalanceLedgerSnapshotmodel withtotalLocked Decimal(20,8)andsnapshotAt(indexed)Campaignrelation extended withbalanceLedgerSnapshotsMigration (
20260715000000_balance_ledger_decimal_and_snapshot)BalanceLedgervia table-copy to rename the column type (SQLite workaround), copying all existing dataBalanceLedgerSnapshottable with all required indexesJob (
src/jobs/balance-ledger-snapshot.job.ts)@Cron(EVERY_HOUR)— groupsBalanceLedgerrows bycampaignIdover the last 24 h window and writes oneBalanceLedgerSnapshotrow per active campaignrun()is public for direct invocation from tests and manual triggersSupporting changes
src/jobs/jobs.module.ts— registersBalanceLedgerSnapshotJoband importsPrismaModulesrc/common/budget/budget.service.ts—toNum()handles bothDecimaland plainnumberso existing mocks remain compatiblesrc/campaigns/campaigns.service.ts—balanceLedger.reducecalls.toNumber()on Decimal amountsTests
src/jobs/balance-ledger-snapshot.job.spec.tstest/balance-ledger-snapshot.e2e-spec.tsThe e2e test directly asserts the acceptance criterion from the issue:
Closes
Closes #261