Skip to content

refactor(subscriptionsync): drop the legacy sync state table and the V2 naming - #5592

Merged
turip merged 1 commit into
mainfrom
feat/subsync-drop-legacy-sync-state
Nov 20, 2026
Merged

turip merged 1 commit into
mainfrom
feat/subsync-drop-legacy-sync-state

Conversation

@turip

@turip turip commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

After #5589, periodic subscription sync schedules from subscription_sync_states_v2 and nothing reads or writes subscription_billing_sync_states any more. This PR:

  • Drops the legacy SubscriptionBillingSyncState Ent schema, the Subscription.billing_sync_state edge and the table.
  • Removes the V2 suffix from the subscriptionsync Go identifiers (SyncStateV2 -> SyncState, SyncStateV2State* -> SyncStateState*, GetSyncStatesV2, RecordSyncResultV2, MarkSubscriptionChangedV2, test spies and helpers, syncstatev2*.go files) and from comments, CLI help and the README.
  • Renames the Ent entity SubscriptionSyncStateV2 to SubscriptionSyncState (package db/subscriptionsyncstate, edge sync_state) while keeping the database objects: the table stays subscription_sync_states_v2, and the FK, check constraint and index names are pinned in the schema.

No behaviour change. Stored state values are unchanged.

Migration

20261119133849_drop_subscription_billing_sync_states.up.sql:

-- drop "subscription_billing_sync_states" table
DROP TABLE "subscription_billing_sync_states";

atlas migrate diff against the schema reports nothing else to change, so the entity rename does not touch subscription_sync_states_v2.

Verification

  • go build ./...
  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic -count=1 ./openmeter/billing/worker/... ./openmeter/subscription/... ./test/subscription/... ./test/billing/... ./cmd/jobs/... ./app/common/... ./openmeter/ent/...
  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic -count=1 -timeout 30m ./tools/migrate/...
  • golangci-lint run ./... (0 issues)
  • atlas migrate validate, atlas migrate diff (no changes), atlas migrate lint --latest 10 (only the expected destructive-change notice for the drop)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Subscription synchronization now uses a unified sync-state system, with existing scheduling, retry, and reconciliation behavior preserved.
    • Removed the separate billing sync-state record; subscription sync results now cover this state.
  • Documentation
    • Clarified when older subscriptions are reconciled and how completed deletion cleanup is handled.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects were found.

Summary

Removes the unused legacy sync-state table and drops V2 from subscription-sync Go names.

  • Subscription sync no longer keeps a separate legacy billing-state table.
  • Subscription sync uses one consistent name for its active state model.

Reviews (2) · Last reviewed commit: "refactor(subscriptionsync): drop the leg..." · Reviewed by Greptile

@turip turip added the keep-open Exempt from stale processing; requires a concrete maintainer reason label Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR renames subscription sync-state APIs and Ent entities to unversioned names while retaining the existing sync-state table names. It updates adapters, services, and tests, and removes the legacy subscription_billing_sync_states table with a rollback migration.

Changes: Subscription sync-state transition

Layer / File(s) Summary
Sync-state contract and schema
openmeter/billing/worker/subscriptionsync/syncstate.go, openmeter/ent/schema/subscriptionsyncstate.go, openmeter/ent/schema/subscription.go, openmeter/ent/schema/subscriptionbillingsync.go, tools/migrate/migrations/20261119133849_drop_subscription_billing_sync_states.*.sql
The sync-state types and Ent entity use unversioned names. Existing sync-state storage names remain. The legacy billing sync-state schema and table are removed, with a rollback migration provided.
Adapter persistence and reconciliation queries
openmeter/billing/worker/subscriptionsync/adapter.go, openmeter/billing/worker/subscriptionsync/adapter/*.go
Persistence, deletion-cleanup, and reconciliation queries use the unversioned sync-state contract. Adapter tests continue to cover persistence, filtering, revisions, and rollback.
Service integration and lifecycle coverage
openmeter/billing/worker/subscriptionsync/{service.go,syncstate.go,deletion.go,README.md}, openmeter/billing/worker/subscriptionsync/{hooks,reconciler,service}/..., cmd/jobs/billing/subscriptionsync/sync.go, test/subscription/custom_currency_lifecycle_test.go
Services, hooks, and lifecycle tests use the unversioned APIs and states. The CLI help and README update their sync-state descriptions.

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

Change: Refactor

Possibly related PRs

Suggested labels: kind/refactor

Suggested reviewers: borosr, tothandras, borbelyr-kong

Merge Risk: Minimal · up to 23238

This is a naming and cleanup refactor that keeps the existing sync-state table and its stored values. It drops only the unused legacy billing sync-state table, with a rollback migration provided. No merge-blocking risk was found. Apply the required release-note label before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the refactor scope and the two main changes: removing the legacy sync state table and removing the V2 naming. The raw summary shows the legacy SubscriptionBillingSyncState schema and t…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the refactor scope and the two main changes: removing the legacy sync state table and removing the V2 naming. The raw summary shows the legacy SubscriptionBillingSyncState schema and table removed, and the V2 identifiers renamed across the subscriptionsync package, adapters, tests, and Ent schema. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8e0f7da and 232389f.

Files ignored due to path filters: 35

  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/cursor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/ent.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/expose.go is excluded by !**/ent/db/**
  • openmeter/ent/db/hook/hook.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/paginate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/predicate/predicate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate/subscriptionbillingsyncstate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionbillingsyncstate_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate/subscriptionsyncstate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstate_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscriptionsyncstatev2_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/tx.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing: 29

  • cmd/jobs/billing/subscriptionsync/sync.go
  • openmeter/billing/worker/subscriptionsync/README.md
  • openmeter/billing/worker/subscriptionsync/adapter.go
  • openmeter/billing/worker/subscriptionsync/adapter/deletion.go
  • openmeter/billing/worker/subscriptionsync/adapter/deletion_test.go
  • openmeter/billing/worker/subscriptionsync/adapter/reconciliation.go
  • openmeter/billing/worker/subscriptionsync/adapter/reconciliation_test.go
  • openmeter/billing/worker/subscriptionsync/adapter/syncstate.go
  • openmeter/billing/worker/subscriptionsync/adapter/syncstate_test.go
  • openmeter/billing/worker/subscriptionsync/deletion.go
  • openmeter/billing/worker/subscriptionsync/hooks/hook.go
  • openmeter/billing/worker/subscriptionsync/reconciler/reconciler.go
  • openmeter/billing/worker/subscriptionsync/service.go
  • openmeter/billing/worker/subscriptionsync/service/base_test.go
  • openmeter/billing/worker/subscriptionsync/service/service.go
  • openmeter/billing/worker/subscriptionsync/service/sync.go
  • openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_lock_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_state_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_test.go
  • openmeter/billing/worker/subscriptionsync/service_test.go
  • openmeter/billing/worker/subscriptionsync/syncstate.go
  • openmeter/billing/worker/subscriptionsync/syncstate_test.go
  • openmeter/ent/schema/subscription.go
  • openmeter/ent/schema/subscriptionbillingsync.go
  • openmeter/ent/schema/subscriptionsyncstate.go
  • test/subscription/custom_currency_lifecycle_test.go
  • tools/migrate/migrations/20261119133849_drop_subscription_billing_sync_states.down.sql
  • tools/migrate/migrations/20261119133849_drop_subscription_billing_sync_states.up.sql
Files with no reviewable changes: 1

  • openmeter/ent/schema/subscriptionbillingsync.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Base automatically changed from worktree-subsync-v2-scheduler to main November 19, 2026 15:22
…V2 naming

Periodic subscription sync no longer reads or writes
subscription_billing_sync_states, so drop its Ent schema, the
Subscription.billing_sync_state edge and the table itself.

With only one sync state left, rename the SubscriptionSyncStateV2 Ent
entity to SubscriptionSyncState and drop the V2 suffix from the
subscriptionsync types, adapter methods, tests and README. The table
stays subscription_sync_states_v2: the schema pins the table, index and
foreign key names so the migration only drops the legacy table.
@turip
turip marked this pull request as ready for review November 20, 2026 09:54
@turip
turip force-pushed the feat/subsync-drop-legacy-sync-state branch from db4b0d5 to 232389f Compare November 20, 2026 09:54
@turip
turip requested a review from a team as a code owner November 20, 2026 09:54
@turip turip added the kind/refactor Code refactor, cleanup or minor improvement label Nov 20, 2026
@turip
turip enabled auto-merge (squash) November 20, 2026 10:13
@turip
turip merged commit dc2b82d into main Nov 20, 2026
33 of 34 checks passed
@turip
turip deleted the feat/subsync-drop-legacy-sync-state branch November 20, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-open Exempt from stale processing; requires a concrete maintainer reason kind/refactor Code refactor, cleanup or minor improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants