fix(user): case-insensitive mail lookup to prevent duplicate accounts#3855
Draft
Blume1977 wants to merge 1 commit into
Draft
fix(user): case-insensitive mail lookup to prevent duplicate accounts#3855Blume1977 wants to merge 1 commit into
Blume1977 wants to merge 1 commit into
Conversation
After the MSSQL->PostgreSQL cutover (#3620), the duplicate-detection lookup `getUsersByMail` used an exact, case-sensitive `mail = ?` comparison. Accounts created before the input lowercase-normalization (#2695) hold mixed-case mails, so the lookup no longer matched them and a second account could be created for the same address (e.g. `Samuel.kullmann@...` vs `samuel.kullmann@...`). - getUsersByMail now compares LOWER(mail) = :mail (input lowercased) - migration lowercases legacy user_data.mail and recommendation.recommendedMail - migration adds a non-unique functional index on LOWER(mail) - specs cover the case-insensitive lookup and the conflict path The UNIQUE variant of the index is intentionally deferred to a separate, gated migration once the existing duplicate accounts are merged.
|
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.
Problem
A user ended up with two
userDataaccounts for the same e-mail differing only in case — e.g.Samuel.kullmann@startmail.com(328304, created 2025-07-29, Active) andsamuel.kullmann@startmail.com(396215, created 2026-05-23, KycOnly).Root cause (regression from the PSQL migration #3620):
Util.toLowerCaseTrim) only arrived with Fix case-sensitive email comparison issues #2695 (2025-12-23) → accounts created earlier hold mixed-case mails.getUsersByMailcomparedmailby exact equality.Changes (PR 1 of 2)
getUsersByMailnow comparesLOWER(mail) = :mailwith a lowercased parameter (Rawoperator, matching the existing repo style inuser.repository.ts). Fixes all 5 callers centrally (mail-login reuse,checkMailconflict/merge, recommendation ×2, compliance search).1781015951873-NormalizeUserDataMailLowercase:user_data.mailandrecommendation.recommendedMail,IDX_user_data_mail_loweronLOWER(mail).LOWER(...)= :mailwith lowercased param;checkMailraisesConflictExceptionon a case-variant duplicate.Deliberately deferred to PR 2 (gated)
The UNIQUE functional index is a separate migration, to be merged only after the existing duplicate accounts are resolved (the
CREATE UNIQUE INDEXwould otherwise fail on current data). Its predicate must mirror the dedup set and exclude merged/blocked rows (which legitimately retain their mail):Operational follow-up (Ops/Compliance, not code)
Audit + merge existing duplicates:
Includes the reported case (master 328304 / slave 396215). Unmergeable pairs (AML / verified-name mismatch / blocked) need a manual compliance decision.
Verification
jestuser-data.service spec (4) + account-merge specs (12) green.node --check.