Skip to content

Reconcile Pay customers on person merge - #2531

Open
maebeale wants to merge 1 commit into
mainfrom
maebeale/paycustomer-dedupe
Open

maebeale wants to merge 1 commit into
mainfrom
maebeale/paycustomer-dedupe

Conversation

@maebeale

@maebeale maebeale commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

🤖 suggested review level: 3 Read 📖 contained merge-time reconciliation of Pay customers

Merging two billable people left their Stripe/Pay data behind: pay_customers were skipped by the deduper (deferred), so the deleted person's customer + charges were orphaned, and when both people had a default customer the survivor ended up with two — making Pay's payment_processor (has_one … default: true) ambiguous.

  • Move pay_customers off DEFERRED so ModelDeduper reassigns them (charges/subscriptions/payment_methods follow via customer_id) to the survivor.
  • Skip soft-delete unique indexes in the collision check — a [owner, deleted_at] index doesn't bound live rows to one per owner in MySQL (NULLs are distinct), so two live customers move rather than one being destroyed.
  • PersonServices::ReconcileDefaultPayCustomer (in after_merge) settles the survivor to a single default — its own pre-merge default, else the newest — demoting the rest.

Base automatically changed from maebeale/check-person-license-number to main September 10, 2026 14:07
Move pay_customers off DEFERRED so ModelDeduper reassigns them (and their charges/
subscriptions via customer_id) to the survivor, and skip soft-delete unique indexes
(a [owner, deleted_at] index doesn't bound live rows in MySQL) so colliding live
customers move rather than one being destroyed. Then ReconcileDefaultPayCustomer
settles the survivor to a single default customer (its own pre-merge default, else
the newest) so Pay's payment_processor isn't ambiguous.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maebeale
maebeale force-pushed the maebeale/paycustomer-dedupe branch from 2ff3f0e to 74e2ffd Compare September 10, 2026 14:08
@maebeale
maebeale requested review from jmilljr24 and a lite review from Copilot and removed request for Copilot September 10, 2026 14:30
@maebeale
maebeale marked this pull request as ready for review September 10, 2026 14:30
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