CS-656 Create script to Migrate all users from old domain to new domain - remove duplicate people records#3304
CS-656 Create script to Migrate all users from old domain to new domain - remove duplicate people records#3304github-actions[bot] wants to merge 7 commits into
Conversation
…ail domain migration
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
4 issues found across 1 file
Confidence score: 2/5
- In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, there is no guard foroldEmail === newEmail, so a self-merge can delete the very user/member being kept; merging as-is risks destructive data loss on valid-looking input — add an explicit equality short-circuit before any delete/update steps. - In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, the training completion migration dropsidand then later updates byid, which can make that migration fail or silently affect zero rows; this creates a concrete partial-migration/regression risk — keepidin the projection (or change downstream updates to available keys) and verify with a targeted migration test before merging. - In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, resolving members outside the transaction introduces a TOCTOU window where merge targets can change mid-operation, leading to inconsistent merges under concurrency — move member resolution inside the same transaction (or lock rows) before merge. - In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, the final merge log reports deleted IDs as survivors, which can mislead incident response and audits after a bad merge — correct survivor/deleted ID mapping in the log payload before shipping.
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
There was a problem hiding this comment.
2 issues found across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai please review it |
@chasprowebdev I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
3 issues found across 2 files
Confidence score: 2/5
- In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, deletingoldUserbefore re-pointing user-level relations can cascade/null fields likeAuditLog.userId, which risks losing historical attribution after a duplicate merge — migrate those relations to the surviving user first, then delete. - In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts, SOA/ISMSapproverIdvalues are not migrated before old-member deletion, so pending/approved document approver assignments can be cleared as a side effect — add an explicit approver reassignment step before the delete. - In
apps/api/src/trigger/tasks/people/merge-duplicate-user.ts,OffboardingAccessRevocation.revokedByIdis matched using member IDs instead of user IDs, so the actor link can be silently missed and revocation history becomes inaccurate — switch the comparison/update logic to user IDs before merging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/trigger/tasks/people/merge-duplicate-user.ts">
<violation number="1" location="apps/api/src/trigger/tasks/people/merge-duplicate-user.ts:235">
P2: Migrate SOA/ISMS document approverId before deleting the old member. Otherwise pending/approved document approver assignments are nulled during the merge.</violation>
<violation number="2" location="apps/api/src/trigger/tasks/people/merge-duplicate-user.ts:245">
P1: Re-point user-level relations before deleting oldUser. Deleting oldUser currently cascades or nulls historical records such as AuditLog.userId instead of preserving them on the surviving account.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai please review this. |
@chasprowebdev I have started the AI code review. It will take a few minutes to complete. |
This is an automated pull request to merge chas/email-migration-script into dev.
It was created by the [Auto Pull Request] action.
Summary by cubic
Adds Trigger tasks
merge-duplicate-userandmigrate-org-email-domainto consolidate duplicate users after email or domain changes. Fulfills CS-656 by removing duplicate people records across an org during domain migrations.org:{organizationId}tagging; improved logging.signedBy), policy versions, tasks/task items, risks, vendors, findings, comments, audit logs, devices, background checks, trust access requests/grants, and offboarding records.oldEmailtonewEmail.migrate-org-email-domainscans active members, matchesoldDomain→newDomainby local-part with case-insensitive comparison (lowercased emails/domains), triggersmerge-duplicate-userper pair, and returns merged/failed counts and pair results; no-ops if normalized domains are identical.Written for commit 4ae255c. Summary will update on new commits.