Skip to content

Fix legacy Stripe customer linking - #7312

Merged
ComputelessComputer merged 3 commits into
mainfrom
fix/normalize-legacy-stripe-linking
Sep 4, 2026
Merged

Fix legacy Stripe customer linking#7312
ComputelessComputer merged 3 commits into
mainfrom
fix/normalize-legacy-stripe-linking

Conversation

@ComputelessComputer

@ComputelessComputer ComputelessComputer commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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 profiles row or workspace billing. Among eligible matches it prefers customers with active/past_due/unpaid subscriptions, then trialing/paused, then any subscription history, then oldest created / stable id. Email updates only fill stripe_customer_id when it is still null, so existing links are not overwritten.

The first migration backfills null profiles.stripe_customer_id for 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.

@netlify

netlify Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deploy Preview for anarlog canceled.

Name Link
🔨 Latest commit b0834e1
🔍 Latest deploy log https://app.netlify.com/projects/anarlog/deploys/6a9a3f5271ee6d0008c0d36a

@ComputelessComputer
ComputelessComputer force-pushed the fix/normalize-legacy-stripe-linking branch from 7c0511e to f140125 Compare September 4, 2026 03:23
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
ComputelessComputer force-pushed the fix/normalize-legacy-stripe-linking branch from f140125 to 3cf8f46 Compare September 4, 2026 03:31

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ 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.
@ComputelessComputer
ComputelessComputer merged commit ab9eb47 into main Sep 4, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant