Migrare BSUID scheme to whatsapp#6727
Conversation
…coped id Adds a bsuid_to_whatsapp management command that migrates existing contact URNs from the bsuid scheme to the whatsapp scheme, keeping the path unchanged: bsuid:<CC.alphanumeric> -> whatsapp:<CC.alphanumeric>. Phone URNs are never touched - no tel URNs are created and legacy all-digit whatsapp URNs are left as-is. Runs in id-ordered batches, bumps modified_on so flipped contacts reindex, skips a batch on a concurrent-write IntegrityError, and is safe to re-run. A bsuid whose whatsapp target already exists on a different contact in the org is left untouched (uniqueness collision); one that duplicates a whatsapp URN the same contact already has is redundant, so its message/call/event references are moved onto the existing whatsapp URN and the bsuid is dropped. URN.validate/format/normalize now accept a business-scoped user id under the whatsapp scheme in addition to a legacy phone number, so a contact can carry a whatsapp URN holding a BSUID value as a valid URN.
Wire Contact._full_release's URN cleanup through the new ContactURN.has_content() helper instead of hand-rolling the msgs/calls/channel_events check, so the two can't drift. In the bsuid_to_whatsapp command, compute each URN's target whatsapp identity once and reuse it for both the collision lookup and the flip.
|
Claude finished @norkans7's task in 6m 31s —— View job Claude PR Review
SummaryOverall this is a clean, well-scoped migration: the URN model changes correctly split "legacy digit whatsapp" from "business-scoped whatsapp id" without touching phone flows, Non-blocking observations (see inline comments):
Nothing here is a blocker. The behavior around the |
…ex on drop Apply each bsuid_to_whatsapp batch inside a transaction.atomic() so a concurrent- write IntegrityError rolls the whole batch back instead of leaving redundant-drop deletes applied while the flips are skipped. On collision, log the bsuid id range that was skipped so it can be investigated without a DB query. Also assert the redundant-drop path reindexes the contact (modified_on bump).
Address remaining PR feedback on bsuid_to_whatsapp: - Normalize the whatsapp target path (uppercasing the country code) instead of carrying the bsuid path across verbatim, so a legacy lowercase-CC bsuid still collides with its canonical whatsapp id and the flipped URN passes URN.validate. - Build the collision lookup as per-org identity sets (Q(org_id=, identity__in=)) rather than org_id IN ... AND identity IN ..., which is a cross-product that could match another org's identical identity.
No description provided.