Repository navigation
fix: repair usage-based deleted invoice runs - #4673
Conversation
📝 WalkthroughWalkthroughAdds a transactional SQL repair migration for deleted usage-based invoice runs and a Go test that seeds multiple scenarios and checks the resulting deletions, overrides, and charge state. ChangesUsage-based run repair migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
fd26c67 to
e4542f3
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.up.sql (1)
12-167: 🚀 Performance & Scalability | 🔵 TrivialHeads-up on lock footprint for the prod run.
Everything's inside one
BEGIN/COMMIT, which is exactly right for atomicity. Just flagging for the operational side: thebilling_invoice_linesupdate joins on(namespace, charge_id)and the empty-invoice cleanup does a per-invoiceNOT EXISTSscan. The affected set should be small, so this is likely a non-issue, but on large billing tables it's worth confirming there's index support for thecharge_idlookups and running it during a low-traffic window to keep lock contention friendly. No code change needed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.up.sql` around lines 12 - 167, This is an operational review note rather than a code defect: the migration in repair_usagebased_deleted_invoice_runs.up.sql already has the right atomic BEGIN/COMMIT behavior, so no code changes are needed. Keep the current logic in the migration, but if you touch the related billing_invoice_lines or billing_invoices cleanup paths later, verify supporting indexes for the charge_id/namespace lookups and consider running the migration during a low-traffic window.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.up.sql`:
- Around line 12-167: This is an operational review note rather than a code
defect: the migration in repair_usagebased_deleted_invoice_runs.up.sql already
has the right atomic BEGIN/COMMIT behavior, so no code changes are needed. Keep
the current logic in the migration, but if you touch the related
billing_invoice_lines or billing_invoices cleanup paths later, verify supporting
indexes for the charge_id/namespace lookups and consider running the migration
during a low-traffic window.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1f4ffaf4-af0d-4922-b321-187f39e06e23
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (3)
tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.down.sqltools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.up.sqltools/migrate/repair_usagebased_deleted_invoice_runs_test.go
✅ Files skipped from review due to trivial changes (1)
- tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.down.sql
Overview
Soft delete charges that are belonging to deleted standard invoices. This corrects any inconsistencies before the usagebased delete was implemented.
Notes for reviewer
Summary by CodeRabbit
Greptile Summary
This PR adds a data repair for usage-based runs left active after invoice deletion. The main changes are:
Confidence Score: 4/5
This is close, but the repair can still leave affected charges out of normal billing advancement.
tools/migrate/migrations/20260709132435_repair_usagebased_deleted_invoice_runs.up.sql
Important Files Changed
Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: cover usage-based deleted invoice ..." | Re-trigger Greptile
Context used (3)