Skip to content

feat(customcurrency): backfill subscription items with currency - #4895

Merged
chrisgacsal merged 2 commits into
mainfrom
feat/subscrption-currency-backfill
Aug 11, 2026
Merged

feat(customcurrency): backfill subscription items with currency#4895
chrisgacsal merged 2 commits into
mainfrom
feat/subscrption-currency-backfill

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

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_currencies RFC3339 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.

  • Backfills eligible subscription items from their owning subscription.
  • Preserves explicit fiat and custom currencies during migration-up.
  • Adds PostgreSQL coverage for migration-up and rollback behavior.
  • Updates the Atlas migration checksum.

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

Filename Overview
tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.up.sql Backfills missing fiat currencies on eligible priced subscription items and records a timestamped migration annotation.
tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.down.sql Reverts rows selected by the migration annotation.
tools/migrate/subscription_item_currency_backfill_test.go Covers eligible and excluded rows, annotation preservation, timestamps, and migration rollback.
tools/migrate/migrations/atlas.sum Registers the new up migration in the Atlas checksum manifest.

Reviews (2): Last reviewed commit: "refactor: rm validation from up migratio..." | Re-trigger Greptile

Summary by CodeRabbit

  • Data Updates

    • Legacy subscription items now inherit their subscription currency when eligible.
    • Existing custom, explicit, deleted, annotated, and unpriced items remain unchanged.
    • Updates include migration tracking and timestamps while preserving existing metadata.
  • Rollback

    • Backfilled currency values and migration annotations can be safely reverted without removing pre-existing data.
  • Tests

    • Added coverage for backfill eligibility, metadata preservation, timestamps, and rollback behavior.

@chrisgacsal chrisgacsal self-assigned this Aug 10, 2026
@chrisgacsal
chrisgacsal requested review from GAlexIHU and turip August 10, 2026 07:18
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a transactional migration that backfills eligible subscription-item currencies, records migration annotations, supports rollback, and verifies both directions with integration tests.

Changes

Subscription item currency migration

Layer / File(s) Summary
Backfill and rollback migration
tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.*.sql
The up migration copies subscription currencies to eligible priced items and records UTC annotations. The down migration removes only backfilled values and annotations.
Migration integration validation
tools/migrate/subscription_item_currency_backfill_test.go
The test covers legacy, annotated, deleted, explicitly assigned, custom-currency, unpriced, and already-annotated items during migration and rollback.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: area/billing, kind/feature

Suggested reviewers: turip, galexihu

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: backfilling subscription items with currency.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/subscrption-currency-backfill

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chrisgacsal chrisgacsal added the release-note/misc Miscellaneous changes label Aug 10, 2026
@chrisgacsal
chrisgacsal marked this pull request as ready for review August 10, 2026 08:12
@chrisgacsal
chrisgacsal requested a review from a team as a code owner August 10, 2026 08:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f343514 and 66fbeff.

⛔ Files ignored due to path filters (1)
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (3)
  • tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.down.sql
  • tools/migrate/migrations/20260810064730_backfill_subscription_item_currencies.up.sql
  • tools/migrate/subscription_item_currency_backfill_test.go

@chrisgacsal
chrisgacsal merged commit 609f588 into main Aug 11, 2026
28 checks passed
@chrisgacsal
chrisgacsal deleted the feat/subscrption-currency-backfill branch August 11, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants