Skip to content

chore: cleanup project affiliations after the last member organizations row is deleted#3941

Merged
themarolt merged 5 commits intomainfrom
fix/cleanup-project-affiliations-on-member-organizations-delete
Mar 20, 2026
Merged

chore: cleanup project affiliations after the last member organizations row is deleted#3941
themarolt merged 5 commits intomainfrom
fix/cleanup-project-affiliations-on-member-organizations-delete

Conversation

@themarolt
Copy link
Contributor

@themarolt themarolt commented Mar 20, 2026

Note

Medium Risk
Touches transactional delete logic across multiple tables and adds new cleanup deletes, which could unintentionally remove affiliations if the conditions are wrong. Impact is limited to member/org affiliation data and is wrapped in a DB transaction.

Overview
Ensures deleting member work experiences/organizations also removes stale memberSegmentAffiliations for organizations where the member no longer has any non-deleted memberOrganizations rows.

deleteMemberOrganizations now captures affected organizationIds before the delete, deletes any related memberOrganizationAffiliationOverrides, performs the soft/hard delete, and then deletes segment affiliations that no longer have an active work-experience backing them. The profiles worker’s removeMemberOrganizations call is updated to soft-delete member org rows (instead of hard-deleting) so this cleanup runs consistently.

Written by Cursor Bugbot for commit 3c4a7f7. This will update automatically on new commits. Configure here.

…ns row is deleted

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings March 20, 2026 13:23
@github-actions
Copy link
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.

2 similar comments
@github-actions
Copy link
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.

@github-actions
Copy link
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.

Copy link
Contributor

Copilot AI left a comment

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 adds a cleanup step to remove stale manual project affiliation overrides (“memberSegmentAffiliations”) when a member’s last work experience for a given organization is deleted.

Changes:

  • Added a DAL helper to delete memberSegmentAffiliations for a member+org only when no active memberOrganizations rows remain for that org.
  • Invoked that cleanup helper during the public API flow that deletes a work experience.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
services/libs/data-access-layer/src/members/projectAffiliations.ts Adds cleanupMemberSegmentAffiliationsForOrg to conditionally purge segment affiliation overrides when the last active org affiliation is gone.
backend/src/api/public/v1/members/work-experiences/deleteMemberWorkExperience.ts Calls the new cleanup helper after deleting a work experience and before triggering affiliation recalculation.

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

@themarolt themarolt requested a review from joanagmaia March 20, 2026 13:34
Signed-off-by: Uroš Marolt <uros@marolt.me>
@github-actions
Copy link
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.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

joanagmaia
joanagmaia previously approved these changes Mar 20, 2026
Copy link
Contributor

@joanagmaia joanagmaia left a comment

Choose a reason for hiding this comment

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

Left one comment, but for the API issue looks good

Signed-off-by: Uroš Marolt <uros@marolt.me>
@github-actions
Copy link
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.

Signed-off-by: Uroš Marolt <uros@marolt.me>
@github-actions
Copy link
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.

Copy link
Contributor

@joanagmaia joanagmaia left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@themarolt themarolt merged commit bc2e323 into main Mar 20, 2026
9 checks passed
@themarolt themarolt deleted the fix/cleanup-project-affiliations-on-member-organizations-delete branch March 20, 2026 16:41
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.

3 participants