Skip to content

fix(db): keep token_ledger when resetting usage data - #16005

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.52from
pacocartones:fix/usage-reset-keeps-token-ledger
Oct 9, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.52from
pacocartones:fix/usage-reset-keeps-token-ledger

Conversation

@pacocartones

@pacocartones pacocartones commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • resetUsageHistory() no longer deletes token_ledger. The table is the record behind token balances and transfer idempotency keys, not usage analytics, so a usage reset must not change balances or free idempotency keys.
  • deletedTokenLedger stays in the result and in the purge API response (always 0), so the response shape does not change.

Related Issues

Validation

  • Change type: DB
  • New test tests/unit/usage-history-reset-token-ledger.test.ts: fails on the base (ledger empty after the reset), passes with the change; tests/unit/usage-history-reset.test.ts still passes
  • npm run lint (whole repo) and prettier --check on the touched files pass on the branch
  • Reconciled with the current release base before opening

Tests Added Or Updated

  • tests/unit/usage-history-reset-token-ledger.test.ts (new): seeds a grant and a transfer older than a day and runs resetUsageHistory("1d") and ("all"); asserts the rows, getBalance() and the idempotency of a retried transfer.

Coverage Notes

  • Touches src/lib/db/cleanup.ts only (removes one reset target, documents one field); covered by the new test.

Reviewer Notes

resetUsageHistory() listed token_ledger among the tables it empties, so
Settings > Storage > Reset usage data deleted the token transfer record that
balances are computed from (getBalance) and that idempotency keys live in:
balances changed and an already-applied transfer could be applied again.
token_ledger is not usage analytics. Remove it from the reset targets; the
deletedTokenLedger field stays (always 0) so the API response keeps its shape.
@diegosouzapw
diegosouzapw merged commit ac8723a into diegosouzapw:release/v3.8.52 Oct 9, 2026
29 of 51 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @pacocartones — resetting usage history no longer deletes token_ledger, so balances survive a 1d or all reset. The response still reports deletedTokenLedger as 0. This is in the upcoming release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(backend): preserve token balances when resetting usage data

2 participants