You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backfill missing subscription sync revisions and require both revision columns so sync can read an existing row's revision directly. The backfill uses om_func_generate_ulid(), fills only NULL fields, and assigns one shared token when both fields are missing. A following migration enforces NOT NULL without adding defaults.
Change the domain revision fields to strings and rename the adapter operation and input to RecordSyncResultV2 and RecordSyncResultV2Input, with no compatibility stubs. Recording cleanup requires the revision observed under the billing lock. Inserts initialize both revisions; conflict updates acknowledge only the captured revision and never overwrite a parallel subscription edit's current revision. Sync generates a ULID only when no v2 row exists.
Notes for reviewer
V2 writes remain limited to successful cleanup. Ordinary syncs, dry runs, and failed transactions retain their existing behavior.
The data backfill preserves populated revisions and cleanup metadata and is safe to rerun. Downgrade retains backfilled values and removes the NOT NULL constraints.
Tests cover all NULL combinations, preservation of existing equal or different revisions, reruns, missing-revision rejection, constraint enforcement, downgrade, and revision changes during cleanup.
Validated after rebasing onto origin/main: PostgreSQL-backed subscription-sync tests, focused backfill and upgrade/downgrade tests, scoped fast lint, Ent regeneration, and Atlas validation.
Summary by CodeRabbit
Improvements
Subscription sync now requires both revision values to be present. Existing records are backfilled while preserving revisions already stored.
Sync results record the revision observed during synchronization without overwriting a newer current revision.
Bug Fixes
Cleanup acknowledgments no longer initialize or overwrite the current revision when recording sync results, helping preserve revision state across cleanup and synchronization.
Confidence Score: 5/5
The PR appears safe to merge; no blocking issues remain.
Summary
This PR backfills missing subscription revisions, requires both revision columns, and records cleanup results without replacing a newer current revision.
Every subscription sync row keeps both revision values.
Cleanup records the revision it saw without replacing a newer one.
No actionable comments were generated in the recent review.
Walkthrough
The v2 subscription sync contract now requires both revision fields. A migration backfills missing values before adding NOT NULL constraints. Sync records the observed revision through RecordSyncResultV2; new rows receive that revision in both fields, while conflicts preserve current_subs_revision.
Changes: V2 subscription sync revision contract
Layer / File(s)
Summary
Backfill and require revision fields openmeter/ent/schema/subscriptionsyncstatev2.go, tools/migrate/migrations/*subscription_sync_revisions*.sql, tools/migrate/subscription_sync_revisions_test.go
The migration backfills missing revision values, then requires both columns. Migration tests cover backfill behavior, constraints, and rollback.
Define and persist sync results openmeter/billing/worker/subscriptionsync/syncstatev2.go, openmeter/billing/worker/subscriptionsync/adapter/syncstatev2.go, openmeter/billing/worker/subscriptionsync/adapter/*test.go
The adapter records a supplied observed revision. New rows use it for both revision fields. Conflict updates do not change current_subs_revision.
Use the revision contract in reconciliation openmeter/billing/worker/subscriptionsync/service/*, openmeter/billing/worker/subscriptionsync/reconciliaton_test.go, openmeter/billing/worker/subscriptionsync/README.md
The service generates a revision when no sync state exists and records cleanup results with RecordSyncResultV2. Tests and the README reflect the required string fields and recording behavior.
This change makes subscription sync revisions required. It backfills missing values first and records the observed revision during cleanup without overwriting a concurrent subscription edit. The reviewed evidence shows no concrete merge-blocking risk, and the migrations have tests and a rollback path.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the subscription sync revision columns become required (NOT NULL), backed by a backfill migration and a string-typed domain model. The refactor(billing) prefix matches…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: the subscription sync revision columns become required (NOT NULL), backed by a backfill migration and a string-typed domain model. The refactor(billing) prefix matches the changed billing worker code and migrations. The title is short, specific, and avoids vague wording, so it is a clear match for the changeset.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
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
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.
Overview
Backfill missing subscription sync revisions and require both revision columns so sync can read an existing row's revision directly. The backfill uses
om_func_generate_ulid(), fills only NULL fields, and assigns one shared token when both fields are missing. A following migration enforcesNOT NULLwithout adding defaults.Change the domain revision fields to strings and rename the adapter operation and input to
RecordSyncResultV2andRecordSyncResultV2Input, with no compatibility stubs. Recording cleanup requires the revision observed under the billing lock. Inserts initialize both revisions; conflict updates acknowledge only the captured revision and never overwrite a parallel subscription edit's current revision. Sync generates a ULID only when no v2 row exists.Notes for reviewer
origin/main: PostgreSQL-backed subscription-sync tests, focused backfill and upgrade/downgrade tests, scoped fast lint, Ent regeneration, and Atlas validation.Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no blocking issues remain.Summary
This PR backfills missing subscription revisions, requires both revision columns, and records cleanup results without replacing a newer current revision.
Reviews (2) · Last reviewed commit: "fix(billing): document revision backfill..." · Reviewed by Greptile