Fix legacy Stripe customer linking - #7312
Merged
Merged
Conversation
✅ Deploy Preview for anarlog canceled.
|
ComputelessComputer
force-pushed
the
fix/normalize-legacy-stripe-linking
branch
from
September 4, 2026 03:23
7c0511e to
f140125
Compare
Match billing identities case-insensitively, prefer customers with subscription history, and backfill unlinked profiles.
Exclude deleted customers, serialize normalized-email claims, and keep ambiguous or deleting profiles out of the backfill.
ComputelessComputer
force-pushed
the
fix/normalize-legacy-stripe-linking
branch
from
September 4, 2026 03:31
f140125 to
3cf8f46
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3cf8f46. Configure here.
Preserve paused and workspace-owned customers during legacy matching, with regression coverage.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Match billing identities case-insensitively, prefer customers with subscription history, and backfill unlinked profiles.
Note
High Risk
Changes SECURITY DEFINER auth triggers and a one-time profile backfill that sets
stripe_customer_id, which directly affects billing identity and could mis-link or skip subscriptions if matching rules are wrong.Overview
Replaces naive Stripe auto-linking on signup and email change with case-insensitive, trimmed email matching, transactional advisory locks per email, and deterministic customer choice when multiple Stripe records share an address.
Linking now skips deleted Stripe customers and IDs already tied to another
profilesrow or workspace billing. Among eligible matches it prefers customers with active/past_due/unpaid subscriptions, then trialing/paused, then any subscription history, then oldestcreated/ stableid. Email updates only fillstripe_customer_idwhen it is still null, so existing links are not overwritten.The first migration backfills null
profiles.stripe_customer_idfor legacy users (unique normalized email only, excluding pending account deletion jobs) using the same ranking rules. Follow-up migrations re-apply the hardened trigger definitions without changing that behavior. pgTAP coverage expands for mixed case, duplicate customers, deleted customers, workspace billing collisions, and email-update paths.Reviewed by Cursor Bugbot for commit b0834e1. Bugbot is set up for automated code reviews on this repo. Configure here.