diff --git a/graphql/migrations/20241017080000-article-passwords-cleanup.js b/graphql/migrations/20241017080000-article-passwords-cleanup.js new file mode 100644 index 000000000..7e9ee8f86 --- /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 () { + return null +}