Repository navigation
feat(customcurrency): materialize subscription item currencies - #4742
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughSubscription items now snapshot fiat or managed custom currency references. Subscription and add-on flows materialize currencies before persistence. Repositories and migrations enforce currency invariants. Workflow construction now validates dependencies and returns initialization errors. ChangesSubscription currency support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Plan
participant SubscriptionService
participant CurrencyResolver
participant SubscriptionSpec
participant SubscriptionItemRepo
participant Database
Plan->>SubscriptionService: Provide CurrencyReference
SubscriptionService->>SubscriptionSpec: MaterializeRateCardCurrencies
SubscriptionService->>CurrencyResolver: ResolveCurrenciesForSubscriptionSpec
SubscriptionService->>SubscriptionItemRepo: Create materialized item
SubscriptionItemRepo->>Database: Store currency and custom_currency_id
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@openmeter/ent/schema/subscription.go`:
- Around line 273-277: Make custom-currency relationships tenant-scoped end to
end: update the subscription schema edge to use namespace and currency ID,
regenerate the migration and extend its database test to reject cross-namespace
currencies; update the mapping hydration path to reject namespace mismatches and
the subscription item save path to validate managed-currency ownership, adding
repository coverage for cross-namespace identities. Apply these changes at
openmeter/ent/schema/subscription.go:273-277,
tools/migrate/migrations/20260717150347_add_subscription_item_currency_references.up.sql:2,
tools/migrate/subscription_item_currency_references_test.go:133-149,
openmeter/subscription/repo/mapping.go:131-135,
openmeter/subscription/repo/subscriptionitemrepo.go:170-175, and
openmeter/subscription/repo/subscriptionitemrepo_test.go:65-129.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6b6f6390-f688-448a-9c63-065d54815580
⛔ Files ignored due to path filters (18)
openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency/customcurrency.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency/where.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency_create.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency_query.gois excluded by!**/ent/db/**openmeter/ent/db/customcurrency_update.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/where.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_create.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_query.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (25)
app/common/subscription.goopenmeter/ent/schema/custom_currencies.goopenmeter/ent/schema/subscription.goopenmeter/productcatalog/subscription/plan.goopenmeter/subscription/addon/diff/apply.goopenmeter/subscription/addon/diff/apply_test.goopenmeter/subscription/plan.goopenmeter/subscription/repo/mapping.goopenmeter/subscription/repo/subscriptionitemrepo.goopenmeter/subscription/repo/subscriptionitemrepo_test.goopenmeter/subscription/service/currency_materialization_test.goopenmeter/subscription/service/service.goopenmeter/subscription/service/sync.goopenmeter/subscription/subscriptionspec.goopenmeter/subscription/testutils/service.goopenmeter/subscription/workflow/service/addon_test.goopenmeter/subscription/workflow/service/service.goopenmeter/subscription/workflow/service/service_test.goopenmeter/subscription/workflow/service/subscription.goopenmeter/subscription/workflow/service/subscription_test.gotest/billing/subscription_suite.gotest/customer/testenv.gotools/migrate/migrations/20260717150347_add_subscription_item_currency_references.down.sqltools/migrate/migrations/20260717150347_add_subscription_item_currency_references.up.sqltools/migrate/subscription_item_currency_references_test.go
5437aab to
14ba071
Compare
1230145 to
abd63d4
Compare
abd63d4 to
9e8ec70
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In
`@tools/migrate/migrations/20260805102531_add_subscription_item_currency_constraints.up.sql`:
- Line 2: Update the Ent schema constraint that defines subscription-item
currency validation so custom currency codes are verified against the currency
identified by custom_currency_id, rather than only checking that both are
present. Regenerate the migration through the project’s Atlas/migrate workflow
instead of editing the SQL directly, and add a regression case covering a valid
but mismatched custom code and ID that must be rejected.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c97c8139-4b55-4e3b-bc84-4333730925e1
⛔ Files ignored due to path filters (10)
openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/where.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_create.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (11)
openmeter/ent/schema/subscription.goopenmeter/subscription/README.mdopenmeter/subscription/repo/mapping.goopenmeter/subscription/repo/subscriptionitemrepo.goopenmeter/subscription/repo/subscriptionitemrepo_test.goopenmeter/subscription/service/currency_materialization_test.gotools/migrate/migrations/20260805102202_add_subscription_item_currency_references.down.sqltools/migrate/migrations/20260805102202_add_subscription_item_currency_references.up.sqltools/migrate/migrations/20260805102531_add_subscription_item_currency_constraints.down.sqltools/migrate/migrations/20260805102531_add_subscription_item_currency_constraints.up.sqltools/migrate/subscription_item_currency_references_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
- openmeter/subscription/repo/subscriptionitemrepo_test.go
- openmeter/subscription/repo/subscriptionitemrepo.go
- openmeter/ent/schema/subscription.go
- openmeter/subscription/service/currency_materialization_test.go
- openmeter/subscription/repo/mapping.go
84a04d8 to
8f0d177
Compare
8f0d177 to
5d2efe2
Compare
Summary
Rollout boundary
This is the expand-and-write breakpoint for subscription custom currencies.
Subscription.Currencykeeps its current meaningDeployed environments can backfill existing rows after this version is rolled out. The semantic change can then land separately.
Validation
make generatemake lint-goPOSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/subscription/... -count=1test/notificationfailure because Svix was not running on127.0.0.1:8071Summary by CodeRabbit
Greptile Summary
This PR materializes effective currencies on subscription items. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (8): Last reviewed commit: "fix: currency ns validation for susbcrip..." | Re-trigger Greptile
Context used (3)