From 5e538a8eb2336ba83d140f0e57a97c563363a5a6 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Wed, 2 Feb 2022 17:24:06 +0100 Subject: [PATCH] Remove unused fields, and collections, and indexes --- ...0241017080000-article-passwords-cleanup.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 graphql/migrations/20241017080000-article-passwords-cleanup.js diff --git a/graphql/migrations/20241017080000-article-passwords-cleanup.js b/graphql/migrations/20241017080000-article-passwords-cleanup.js new file mode 100644 index 000000000..f4f89abee --- /dev/null +++ b/graphql/migrations/20241017080000-article-passwords-cleanup.js @@ -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) { + return null +}