fix(pioneer): derive cycle figures from ledger + ledger-trail the pool reset#33
Merged
Merged
Conversation
…l reset The Pioneer drip cycle counters could orphan: a full-account reset wiped the pioneer_drip ledger + zeroed pioneer_credits_balance, but left users.pioneer_drip_credits_this_cycle / _days_this_cycle untouched — so /account/pioneer/status reported "+15,600 this cycle (13 drips)" with ZERO pioneer_drip ledger rows and a 0 pool. Same denormalized-counter drift class as the monthly_calls_count / invoice issue. 1. /account/pioneer/status now DERIVES drip_credits_this_cycle (= the pioneer_drip ledger sum this cycle, same source as credits_earned_this_month) and drip_days_this_cycle (= distinct Pacific drip days from the ledger) instead of reading the denormalized users.pioneer_drip_* columns. The displayed figure can no longer disagree with the credits actually dripped. 2. The monthly cycle-reset now writes a 'pioneer_reset' credit_transactions row for the forfeited pool when it zeroes pioneer_credits_balance — the pool never drops to 0 without a ledger trail. Uses a CTE to capture the pre-zero balance; RETURNING fires only when the month-gate matches, so a no-op reset writes no row and zeroes no counters (also fixes latent over-zeroing of the counters). (The orphaned 15,600/13 counter on the affected account was separately zeroed in the DB to match its empty ledger.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Pioneer cycle counters could orphan: a full-account reset wiped the
pioneer_dripledger + zeroed the pool but leftusers.pioneer_drip_*— so the dashboard showed +15,600 (13 drips) with 0 ledger rows and a 0 pool./account/pioneer/statusderivesdrip_credits_this_cycle/drip_days_this_cyclefrom thepioneer_dripledger (same source ascredits_earned_this_month), not the denormalizedusers.pioneer_drip_*columns → can't orphan again.pioneer_resetledger row for the forfeited pool when it zeroespioneer_credits_balance(CTE captures pre-zero value; RETURNING gates it to real resets) → pool never hits 0 without a trail.🤖 Generated with Claude Code