Skip to content

fix(user): unique index on LOWER(mail) [GATED — merge after duplicate cleanup]#3856

Draft
Blume1977 wants to merge 1 commit into
developfrom
fix/user-mail-unique-index
Draft

fix(user): unique index on LOWER(mail) [GATED — merge after duplicate cleanup]#3856
Blume1977 wants to merge 1 commit into
developfrom
fix/user-mail-unique-index

Conversation

@Blume1977

Copy link
Copy Markdown
Collaborator

⚠️ Do NOT merge until the duplicate-account cleanup is complete

Follow-up to #3855. This replaces the non-unique LOWER(mail) index with a UNIQUE partial index, permanently preventing duplicate accounts for the same e-mail.

CREATE UNIQUE INDEX fails on deploy if any case-insensitive duplicate mail still exists. This PR may only be merged once the pre-check returns zero rows:

SELECT LOWER(mail) AS mail_lc, array_agg(id ORDER BY id) AS ids, count(*) AS n
FROM user_data WHERE mail IS NOT NULL
GROUP BY LOWER(mail) HAVING count(*) > 1 ORDER BY n DESC;

Index predicate (deliberate)

CREATE UNIQUE INDEX "IDX_user_data_mail_lower" ON "user_data" (LOWER("mail"))
WHERE "mail" IS NOT NULL AND "status" IN ('Active','NA','KycOnly','Deactivated');

The predicate mirrors the dedup set used by getUsersByMail(onlyValidUser) and excludes Merged/Blocked rows:

  • merged slaves keep their mail (mergeUserData does not null it),
  • blocked duplicates may keep theirs for audit.

A bare WHERE mail IS NOT NULL would fail on every historical merge pair and would break future merges. Scoping to the active set keeps the uniqueness guarantee consistent with the lookup that enforces it.

Depends on

Follow-up to #3855. Replaces the non-unique LOWER(mail) index with a
UNIQUE partial index so duplicate accounts for the same address can no
longer be created.

GATED: must not be deployed until existing duplicate mails are resolved,
otherwise CREATE UNIQUE INDEX fails. The predicate mirrors the
getUsersByMail dedup set and excludes Merged/Blocked rows, which
legitimately retain their mail.
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

⚠️ Unverified Commits (1)

The following commits are not signed/verified:

  • f93c02a fix(user): unique index on LOWER(mail) to enforce e-mail uniqueness (Blume1977)
How to sign commits
# SSH signing (recommended)
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true

# Re-sign last commit
git commit --amend -S --no-edit
git push --force-with-lease

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