KamoCRM

One e-mail address, one account — and leads follow the address

Featurekamo-shared-library
Shipped
November 13, 2026 at 7:13 AM UTC
Author
Kamo
Commit
59a6f76

AccountEmailIdentity **************** is the one place the rule lives: - findByEmail(org, email): the org's account holding the address, ignoring case and surrounding space (ContactCanon.email, the contact-point key). Served by the hand-made expression index ix_accounts_org_email (org_id, lower(email)), created 2026-11-12 and declared here on Account by name. - linkLeadsAfterCommit(account): every lead in the org with that address and NO account yet joins it. Found through lead_contact_points (IX_LCP_ORG_KIND_VALUE), never the leads table; 15 of 799,483 leads with an address lacked a row on 2026-11-12. Background, chunks of 200, each chunk its own REQUIRES_NEW transaction, history (lead + account timelines) in another after it, so a history failure never undoes a link. - linkLeadAfterCommit(lead): a lead with no account joins the account holding its address. One indexed lookup after the commit. - reusableForMember: for creators of member-OWNED accounts (billing). The member's own account is reused; an unowned one only on a VERIFIED address (owning an account shows its loans and documents, and the borrower portal marks typed addresses verified); another person's never. Never fails the work that triggered it: after commit, own transaction, every failure logged and swallowed. A lead already on an account is never moved. Not a unique index on purpose: a violation inside a loan sync or lead import would fail the very work that must not fail. Wired here: **************** (every intake, import, manual and SI lead path), RetailService create/update (a taken address is refused with a sentence), StoreSyncWriter (already reused by e-mail; now links leads). SecurityService (manual accounts, the external MLOS loan sync, billing setup) and BillingService follow.

All changes

Like what you see shipping?

All of it arrives in your workspace on its own. Start on the free plan and read this page again in a month.

Start Free ForeverView Pricing