Skip to content

Commit

Permalink
Remove unused fields, and collections, and indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Parisot authored and thom4parisot committed Oct 17, 2024
1 parent 7084e6d commit 5e538a8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions graphql/migrations/20241017080000-article-passwords-cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

exports.up = async function (db) {
const mongo = await db._run("getDbInstance")
const collections = (await mongo.listCollections().toArray()).map(c => c.name)


// 1. remove article owners (moved into owner+contributors)
await mongo.collection('articles').updateMany({}, { $unset: { owners: ''}})

// 2. remove linked collections relations
await mongo.collection('users').updateMany({}, { $unset: { tokens: '', passwords: '' }})

// 3. remove Password related stuff
if (collections.includes('passwords')) {
await mongo.collection('passwords').drop()
}

// 4. remove Token related stuff
if (collections.includes('tokens')) {
await mongo.collection('tokens').drop()
}

return mongo.close()
}

exports.down = function (db) {

Check failure on line 26 in graphql/migrations/20241017080000-article-passwords-cleanup.js

View workflow job for this annotation

GitHub Actions / build / build

'db' is defined but never used

Check failure on line 26 in graphql/migrations/20241017080000-article-passwords-cleanup.js

View workflow job for this annotation

GitHub Actions / build / build

'db' is defined but never used
return null
}

0 comments on commit 5e538a8

Please sign in to comment.