feat(customcurrency): backfill subscription items with currency - #4895
Conversation
📝 WalkthroughWalkthroughThis PR adds a transactional migration that backfills eligible subscription-item currencies, records migration annotations, supports rollback, and verifies both directions with integration tests. ChangesSubscription item currency migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ 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 |
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/20260810064730_backfill_subscription_item_currencies.up.sql`:
- Around line 14-20: Make the up migration record rollback metadata uniquely
owned by this migration, so it cannot match pre-existing markers; update the
down migration to roll back only rows proven changed by this migration. In
tools/migrate/subscription_item_currency_backfill_test.go lines 149-151, retain
the pre-existing-marker fixture, and at lines 221-223 assert that its annotation
remains after rollback.
🪄 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: e43a122d-2c3d-40c7-b35c-923ddd5e5402
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (3)
tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.down.sqltools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.up.sqltools/migrate/subscription_item_currency_backfill_test.go
Overview
What
Add a database migration that backfills missing currency codes on legacy priced subscription items and marks updated rows with a timestamped migration annotation.
Why
New subscription items already persist their effective currency, but legacy priced items may still have no currency. These rows must be backfilled before enforcing stricter currency constraints.
How
The migration copies the owning subscription’s fiat currency to unannotated priced items with no currency reference. It preserves existing annotations and explicit fiat/custom currencies. Updated rows receive a
dbmigration:backfill_subscription_item_currenciesRFC3339 annotation, which also supports targeted rollback. PostgreSQL migration tests cover backfill, exclusion, preservation, and rollback behavior.This must be merged prior: #4744.
Greptile Summary
The PR adds a data migration that materializes inherited subscription currency on legacy priced items and marks changed rows for rollback.
Confidence Score: 4/5
The PR is not yet safe to merge because rollback can corrupt rows that had the migration marker before migration-up.
The up migration skips pre-marked rows, while the down migration still treats every marked row as migration-owned and clears its currency and marker; this previously reported rollback defect remains outstanding.
Files Needing Attention: tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.down.sql
Important Files Changed
Reviews (2): Last reviewed commit: "refactor: rm validation from up migratio..." | Re-trigger Greptile
Summary by CodeRabbit
Data Updates
Rollback
Tests