feat: added query to remove orphan user org membership#5233
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Greptile SummaryThis PR adds a deletion query to remove orphan organization membership records where Key Changes:
Critical Issue:
Confidence Score: 2/5
Important Files Changed
|
| }; | ||
|
|
||
| const migrateMembershipData = async (knex: Knex) => { | ||
| await knex(TableName.OrgMembership).whereNull("userId").del(); |
There was a problem hiding this comment.
logic: Migration not idempotent - deletion runs every time up() executes, even when tables already exist.
The deletion is outside the idempotency check (if (hasToMigrateMembershipTable)), so re-running will delete from OrgMembership table even after it's been migrated to the new Membership table. This could cause data loss.
| await knex(TableName.OrgMembership).whereNull("userId").del(); | |
| if (hasToMigrateMembershipTable) { | |
| await knex(TableName.OrgMembership).whereNull("userId").del(); | |
| } |
Context
This PR removes orphan organisation membership user data where the user field is null. This caused the simplify membership migration to fail because it expects the user ID to be available.
Screenshots
Steps to verify the change
Type
Checklist
type(scope): short description(scope is optional, e.g.,fix: prevent crash on syncorfix(api): handle null response).