-
-
Notifications
You must be signed in to change notification settings - Fork 10
refactor(organizations): remove org email-invite + drop-invited migration (P4) #3822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
bf3ba7a
feat(organizations): remove org email-invite feature + data migration
PierreBrisorgueil 44d3ba2
fix(organizations): migration $unset via raw collection driver (stric…
PierreBrisorgueil 0e0f81d
fix(organizations): correct MIGRATIONS.md file refs + add leave unit …
PierreBrisorgueil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
72 changes: 72 additions & 0 deletions
72
modules/organizations/migrations/20260610130000-drop-org-invited-memberships.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * Module dependencies | ||
| */ | ||
| import mongoose from 'mongoose'; | ||
|
|
||
| const INVITE_TOKEN_INDEX = 'inviteToken_1'; | ||
|
|
||
| /** | ||
| * Migration: Remove the organization email-invite feature's leftover data. | ||
| * | ||
| * The org-owned email-invite flow (`status:'invited'` memberships carrying an | ||
| * `inviteToken` / `invitedEmail` / `inviteExpiresAt`) has been deleted. This | ||
| * migration cleans up any residual data: | ||
| * - deletes leftover `invited` memberships (often `userId:null` orphans that | ||
| * would otherwise dangle with no corresponding user); | ||
| * - unsets the now-removed invite fields on any surviving membership; | ||
| * - drops the sparse `inviteToken_1` index that backed invite lookups. | ||
| * | ||
| * Uses the RAW collection driver (not the Mongoose model) for both writes: the | ||
| * schema no longer declares `inviteToken` / `invitedEmail` / `inviteExpiresAt`, | ||
| * so a model-based `updateMany` would have strict-mode strip those keys from the | ||
| * `$unset` operator — the driver would receive no `$unset` and the legacy fields | ||
| * would survive forever (the migration would record as executed having changed | ||
| * nothing). Same gotcha the billing migrations document (see | ||
| * `20260502100000-*` and `20260503000200-slim-subscription-drop-period-fields`). | ||
| * | ||
| * Idempotent: re-running is a no-op (no `invited` rows / no invite fields / the | ||
| * index already absent). | ||
| * @returns {Promise<void>} Resolves when the cleanup has completed. | ||
| */ | ||
| export async function up() { | ||
| // Raw collection driver so neither the deleteMany filter nor the $unset is | ||
| // stripped by strict-mode schema enforcement (the model no longer declares | ||
| // the invite fields). Model `Membership` → default collection `memberships`. | ||
| const db = mongoose.connection.db; | ||
| const memberships = db.collection('memberships'); | ||
|
|
||
| // Org email-invite removed; leftover INVITED rows (often userId:null) become orphans → delete. | ||
| await memberships.deleteMany({ status: 'invited' }); | ||
|
|
||
| await memberships.updateMany( | ||
| { $or: [{ inviteToken: { $exists: true } }, { invitedEmail: { $exists: true } }, { inviteExpiresAt: { $exists: true } }] }, | ||
| { $unset: { inviteToken: '', invitedEmail: '', inviteExpiresAt: '' } }, | ||
| ); | ||
|
|
||
| // Check-then-act so absence is the expected path (not an error to swallow) and | ||
| // either outcome is observable. listIndexes throws NamespaceNotFound on a fresh | ||
| // DB with no memberships collection — treat that as "nothing to drop". | ||
| let indexes = []; | ||
| try { | ||
| indexes = await memberships.indexes(); | ||
| } catch (err) { | ||
| if (err?.codeName === 'NamespaceNotFound' || err?.code === 26) { | ||
| console.info('[migration] drop-org-invited-memberships: memberships collection does not exist yet — nothing to drop'); | ||
| return; | ||
| } | ||
| throw err; | ||
| } | ||
|
|
||
| if (indexes.some((ix) => ix.name === INVITE_TOKEN_INDEX)) { | ||
| await memberships.dropIndex(INVITE_TOKEN_INDEX); | ||
| console.info('[migration] drop-org-invited-memberships: dropped legacy inviteToken_1 index'); | ||
| } else { | ||
| console.info('[migration] drop-org-invited-memberships: inviteToken_1 index already absent — skipping drop'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * No-op down migration. The dropped data/index cannot be meaningfully restored. | ||
| * @returns {void} | ||
| */ | ||
| export function down() { console.warn('[migration] drop-org-invited-memberships DOWN: no-op'); } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.