fix: soft delete member segment affiliations for blocked orgs#4170
Merged
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Contributor
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
Contributor
There was a problem hiding this comment.
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
deletedAttomemberSegmentAffiliationsand 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.
themarolt
previously approved these changes
Jun 4, 2026
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
ulemons
reviewed
Jun 4, 2026
ulemons
previously approved these changes
Jun 4, 2026
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds soft-delete support for
memberSegmentAffiliationsso 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
deletedAttomemberSegmentAffiliationsNotes