Repository navigation
refactor(credit): migrate invoice purchase statuses - #4860
Merged
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughThe PR adds a SQL migration for invoice credit purchase statuses, validates related grants and payment states, and removes the equivalent runtime mapping from state-machine construction. PostgreSQL tests cover successful mappings and validation failures. ChangesInvoice credit purchase status migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MigrationTest
participant PostgreSQL
participant StatusMigration
MigrationTest->>PostgreSQL: Create temporary tables and test data
MigrationTest->>StatusMigration: Execute migration
StatusMigration->>PostgreSQL: Validate grants and payment states
StatusMigration->>PostgreSQL: Update purchase statuses
PostgreSQL-->>MigrationTest: Return migrated rows or validation errors
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
Base automatically changed from
feat/invoice-credit-purchase-state-machine
to
main
August 6, 2026 08:18
turip
force-pushed
the
feat/migrate-invoice-credit-purchase-status
branch
from
August 6, 2026 08:21
3baa10b to
31615aa
Compare
turip
marked this pull request as ready for review
August 6, 2026 08:21
borosr
approved these changes
Aug 6, 2026
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
activestatus using their durable credit-grant and invoiced-payment realizationsWhy
This is the migration follow-up to #4859. Moving compatibility into the database lets the invoice credit-purchase state machine operate exclusively on explicit detailed states before cost-basis pinning is implemented.
Ticket: OM-436
Impact
The migration maps invoice purchases as follows:
active.payment.pendingactive.payment.authorizedfinalThe data migration is intentionally not reversed by its down migration because collapsing detailed states would lose lifecycle information.
Validation
make migrate-check-lintmake migrate-check-validatePOSTGRES_HOST=127.0.0.1 go test ./tools/migrate -run '^(TestMigrateInvoiceCreditPurchaseStatuses|TestUpDownUp)$' -count=1go test -tags=dynamic ./openmeter/billing/charges/creditpurchase/service/... -count=1lint-go-fastandlint-go-stylechecks in the Nix CI shellSummary by CodeRabbit
Greptile Summary
The PR migrates legacy invoice-settled credit purchases from the generic active status to detailed lifecycle states, then removes the corresponding runtime compatibility mapper.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Legacy invoice purchase: active] --> B{Valid active credit grant?} B -- No --> X[Abort migration] B -- Yes --> C{Invoiced payment realization} C -- None --> D[active.payment.pending / active] C -- authorized --> E[active.payment.authorized / active] C -- settled --> F[final / final] C -- unsupported --> XReviews (2): Last reviewed commit: "refactor(credit): migrate invoice purcha..." | Re-trigger Greptile