mirror of
https://github.com/we-promise/sure.git
synced 2026-04-11 00:04:47 +00:00
Problem: Transactions were silently failing to import when the provider (e.g., Lunchflow) returned merchant names with inconsistent casing. Root cause discovered when: 1. User A connected their account, synced transactions with merchant "JOHN DOE" 2. User A disconnected their account (but ProviderMerchant records persist) 3. User B connected their account 4. User B had a transaction to the same person but provider returned it as "John Doe" (different casing) 5. Lookup by (source, name) failed to find existing "JOHN DOE" merchant 6. Tried to create new merchant with same provider_merchant_id (derived from MD5 of lowercased name) → unique constraint violation 7. Transaction import failed silently Impact: - Missing transactions caused incorrect account balances (showing negative when they shouldn't) - Balance chart displayed incorrect historical data - Users saw fewer transactions than actually existed in their bank Solution: Look up merchants by provider_merchant_id first (the stable, case-insensitive identifier derived from the normalized merchant name), then fall back to exact name match for backwards compatibility.