Skip to content

Merge duplicate people and companies - #81

Draft
Pallavikumarimdb wants to merge 1 commit into
Noveum:mainfrom
Pallavikumarimdb:feat/merge-duplicate-records
Draft

Pallavikumarimdb wants to merge 1 commit into
Noveum:mainfrom
Pallavikumarimdb:feat/merge-duplicate-records

Conversation

@Pallavikumarimdb

Copy link
Copy Markdown

What changes

Introduces an atomic merge_records business operation and side-by-side review modal that allows users to merge duplicate person or company records into a canonical record while choosing which conflicting fields to keep. Relationships, conversations, meetings, deals/opportunities, actions, tasks, and notes are atomically moved to the canonical record within one transaction, private conversations remain private to their owner, and the merge is logged in change_events.

Closes #42

How you know it works

  • Automated tests added & verified:
    • tests/merge-records.test.ts:
      • Atomicity & Audit trail: Verifies all related entities move in a single transaction, the duplicate record is deleted, and person.merged / company.merged is recorded in change_events.
      • Cross-product relationships: Verifies distinct product relationships are repointed and identical (productId, purpose) combinations are deduplicated cleanly without index collision, stopping duplicate active sequence enrollments.
      • Private conversation ownership & privacy: Verifies conversations keep ownerId and visibility: 'private', so non-owners in teammate context cannot view them after the merge.
      • Organization isolation: Verifies merging records across different organizations is rejected with 404 Not Found.
      • Company merge: Verifies employee companyId repointing and invalidation of pending outbound touch approvals.
      • Concurrency & Self-merge: Verifies version mismatches return 409 Conflict and self-merges are rejected with 400 Bad Request.
      • Operation Catalog Compatibility: Verified via tests/operation-compatibility.test.ts (109 operations passing).
    • tests/merge-ui.test.tsx:
      • Tests candidate search and filtering.
      • Tests side-by-side comparison layout, conflict badge highlighting, and radio field override selection.
      • Tests swapping canonical and duplicate records.
      • Tests payload formatting and dispatch to /api/crm with merge-records.
  • Manual UI checks:
    • Opened person and company records, launched the merge dialog via both the record action dropdown menu and the Ctrl+K command menu.
    • Selected duplicate candidates, previewed field conflicts, swapped canonical orientation, and confirmed merge execution.

Screenshots

(Attach screenshots of the side-by-side review dialog showing the canonical record on the left, the duplicate candidate on the right, and the conflict resolution options).

Checklist

  • bun run verify passes (lint, licenses, types, tests, build, public smoke test)
  • bun run test:files passes if I touched the file library
  • New behaviour has a test that fails without the change
  • Business operations are defined in packages/operations/catalog.ts, so HTTP and MCP stay in step
  • Interface strings are in packages/i18n/translations/en.json
  • Migrations were generated with bun run db:generate and exercised locally (or none were needed)
  • No real contacts, message bodies, credentials or uploaded files are included
  • Docs updated if setup, configuration or behaviour changed

Limitations

None. Merging is locked at the organization level per transaction to prevent race conditions during repointing.

@github-actions

Copy link
Copy Markdown

Thanks for your first pull request to Gravity.

bun run verify runs the same checks as CI, so running it before you push
saves a review round. If you touched business logic, the
reviewer will look for a test that covers another organization, a restricted
product member or a private conversation owner.

A maintainer will review this soon. Ask anything on the thread.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added area: ui Workspace views, dialogs, inspector and command menu area: core Domain services and the operation registry i18n Interface strings and translations tests Test suites and test infrastructure labels Oct 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Domain services and the operation registry area: ui Workspace views, dialogs, inspector and command menu i18n Interface strings and translations tests Test suites and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge duplicate people and companies

1 participant