Skip to content

feat: added cleanup query to remove orphan identity#5237

Merged
maidul98 merged 1 commit intomainfrom
chore/migration-fix
Jan 22, 2026
Merged

feat: added cleanup query to remove orphan identity#5237
maidul98 merged 1 commit intomainfrom
chore/migration-fix

Conversation

@akhilmhdh
Copy link
Member

@akhilmhdh akhilmhdh commented Jan 22, 2026

Context

This PR removes the orphan identity in project and organisation membership identity table that doesn't exist in identity table. When we were running migration for a usecase we found out there was orphan rows and this is to handle that edge case gracefully. The FK didn't exist in both. tables for the identities.

Screenshots

Steps to verify the change

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Read the contributing guide

@akhilmhdh akhilmhdh requested a review from maidul98 January 22, 2026 17:58
@maidul98
Copy link
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 22, 2026

Greptile Summary

Adds data cleanup operations to the membership migration to remove orphaned identity records that reference non-existent identities in the Identity table. Two delete operations were added before migrating data from IdentityOrgMembership and IdentityProjectMembership tables.

  • Deletes orphaned records from IdentityOrgMembership where identityId doesn't exist in Identity table
  • Deletes orphaned records from IdentityProjectMembership where identityId doesn't exist in Identity table
  • Both cleanup operations use whereNotIn subquery pattern to identify orphaned records
  • Migration remains idempotent as cleanup operations only delete invalid data before migration

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes add defensive cleanup operations to handle edge cases discovered during production migrations. The delete operations are properly scoped using subqueries and only remove invalid orphaned data. The migration maintains idempotency and follows the established pattern in the codebase.
  • No files require special attention

Important Files Changed

Filename Overview
backend/src/db/migrations/20251005152640_simplify-membership.ts Adds cleanup queries to remove orphaned identity records from org and project membership tables before migration

@maidul98 maidul98 merged commit 58f5bce into main Jan 22, 2026
12 of 13 checks passed
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.

2 participants