Skip to content

fix: soft delete member segment affiliations for blocked orgs#4170

Merged
skwowet merged 8 commits into
mainfrom
fix/soft-delete-member-segment-affiliations
Jun 5, 2026
Merged

fix: soft delete member segment affiliations for blocked orgs#4170
skwowet merged 8 commits into
mainfrom
fix/soft-delete-member-segment-affiliations

Conversation

@skwowet

@skwowet skwowet commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds soft-delete support for memberSegmentAffiliations so manual segment affiliations can be preserved while being excluded from active affiliation logic.

When an organization affiliation is blocked, related member segment affiliation rows are now soft-deleted as well. This prevents manually created MSAs from keeping activities affiliated to blocked organizations during recalculation, while still retaining the original data through deletedAt.

Changes

  • Add deletedAt to memberSegmentAffiliations
  • Make MSA deletion soft by default, while keeping hard delete available for flows where it is still appropriate
  • Filter soft-deleted MSAs from read paths, project affiliation APIs, OpenSearch, and affiliation recalculation
  • Soft-delete related MSAs when org affiliation blocking or member-org blocking is applied
  • Keep soft-deleted MSAs with the member during merge/unmerge moves so historical rows are not left behind
  • Clean up older member segment affiliation code paths to use the shared MSA helpers consistently

Notes

  • Unblocking an organization does not automatically restore previously soft-deleted MSAs
  • Replacing a member’s project affiliations soft-deletes the previous active rows before inserting the new set

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this Jun 4, 2026
@skwowet skwowet requested review from Copilot and themarolt June 4, 2026 11:04
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@skwowet skwowet requested a review from ulemons June 4, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces soft-delete semantics for memberSegmentAffiliations (MSA) via a new deletedAt column, ensuring manually created affiliations can be retained for historical/audit purposes while being excluded from “active affiliation” logic—especially when an organization affiliation is blocked.

Changes:

  • Add deletedAt to memberSegmentAffiliations and implement a shared helper to soft-delete (default) or hard-delete MSAs.
  • Update read/query paths (DAL, backend services, OpenSearch indexing, affiliation recalculation) to ignore soft-deleted MSAs.
  • When org/member-org affiliation is blocked, soft-delete related MSAs to prevent manual affiliations from keeping activities affiliated to blocked orgs.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/libs/opensearch/src/repo/member.repo.ts Excludes soft-deleted MSAs from the OpenSearch member indexing query.
services/libs/data-access-layer/src/members/segments.ts Excludes soft-deleted MSAs when resolving manual affiliation for a member+segment at a timestamp.
services/libs/data-access-layer/src/members/projectAffiliations.ts Filters soft-deleted MSAs from project-affiliation read APIs; removes legacy hard-delete helper.
services/libs/data-access-layer/src/members/organizations.ts Soft-deletes MSAs during member-org cleanup; soft-deletes MSAs when writing blocked overrides during role moves/merges.
services/libs/data-access-layer/src/members/base.ts Updates “move affiliations between members” to exclude soft-deleted rows (see review comment).
services/libs/data-access-layer/src/member-organization-affiliation/index.ts Excludes soft-deleted MSAs during affiliation activity processing.
services/libs/data-access-layer/src/member_segment_affiliations/index.ts Adds deleteMemberSegmentAffiliations helper (soft by default) and filters soft-deleted rows from MSA read/move helpers.
services/libs/data-access-layer/src/affiliations/index.ts Excludes soft-deleted MSAs in bulk manual affiliation reads.
services/libs/common_services/src/services/member/unmerge.ts Soft-deletes MSAs for orgs whose affiliation is blocked during unmerge restoration.
services/libs/common_services/src/services/common.member.service.ts Uses DAL move-affiliations helper during merge; impacted by the new deletedAt filter.
services/apps/script_executor_worker/src/activities/block-project-organization-affiliations.ts Soft-deletes MSAs when org affiliation policy is newly blocked; minor async flow adjustment.
services/apps/members_enrichment_worker/src/activities/enrichment.ts Soft-deletes MSAs for orgs with blocked affiliation during enrichment updates.
services/apps/data_sink_worker/src/service/organization.service.ts Soft-deletes MSAs for blocked org affiliations when adding orgs to a member.
services/apps/cron_service/src/jobs/inferMemberOrganizationStintChanges.job.ts Soft-deletes MSAs when stint changes cause affiliation blocking.
backend/src/services/segmentService.ts Soft-deletes MSAs when blocking org affiliation via segment service flow.
backend/src/services/organizationService.ts Soft-deletes MSAs when an organization is set to isAffiliationBlocked.
backend/src/services/member/memberOrganizationsService.ts Soft-deletes MSAs when member-org affiliation is blocked.
backend/src/database/repositories/memberSegmentAffiliationRepository.ts Removes legacy repository (replaced by DAL helpers + captureApiChange logic).
backend/src/database/repositories/memberRepository.ts Migrates “set affiliations” to DAL helpers; filters soft-deleted MSAs from affiliation reads and selected moves.
backend/src/database/repositories/member/memberOrganizationAffiliationOverridesRepository.ts Soft-deletes MSAs when setting allowAffiliation=false for a member-org override.
backend/src/database/repositories/member/memberAffiliationsRepository.ts Uses the new MSA delete helper (soft delete by default).
backend/src/database/migrations/V1780460201__add-deleted-at-to-member-segment-affiliations.sql Adds deletedAt column to enable soft-delete semantics.
backend/src/bin/scripts/backfill-email-domain-member-organization-dates.ts Soft-deletes MSAs when writing blocked overrides during backfill.
backend/src/api/public/v1/members/work-experiences/createMemberWorkExperience.ts Soft-deletes MSAs when newly created work experience is blocked by org policy.
backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts Replaces hard-delete of project MSAs with the shared delete helper (soft by default).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/libs/data-access-layer/src/members/base.ts
themarolt
themarolt previously approved these changes Jun 4, 2026
@skwowet skwowet changed the title fix: soft delete member segment affiliations for blocked organizations fix: soft delete member segment affiliations for blocked orgs Jun 4, 2026
skwowet added 2 commits June 4, 2026 16:57
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread backend/src/services/organizationService.ts
ulemons
ulemons previously approved these changes Jun 4, 2026
Copilot AI review requested due to automatic review settings June 5, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread services/libs/data-access-layer/src/members/organizations.ts
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet merged commit ef99959 into main Jun 5, 2026
10 checks passed
@skwowet skwowet deleted the fix/soft-delete-member-segment-affiliations branch June 5, 2026 06:17
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.

4 participants