From 7258ddcf021fec869f8a0e0dd9877d871047f15d Mon Sep 17 00:00:00 2001 From: Liangjun Song <146005915+adai26@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:20:36 +0800 Subject: [PATCH] Merge pull request #20770 from overleaf/ls-drop-unused-collections drop unused collections GitOrigin-RevId: 4b079f15dca349ef6a5aed8d9dcb35478819c2ce --- .../web/app/src/infrastructure/mongodb.js | 2 -- ...0190912145030_create_templates_indexes.mjs | 16 +++++++--- ...0190912145033_create_userstubs_indexes.mjs | 17 +++++++--- ...20241002180623_drop_unused_collections.mjs | 31 +++++++++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 services/web/migrations/20241002180623_drop_unused_collections.mjs diff --git a/services/web/app/src/infrastructure/mongodb.js b/services/web/app/src/infrastructure/mongodb.js index 294cbf538e..62ff5a8f0c 100644 --- a/services/web/app/src/infrastructure/mongodb.js +++ b/services/web/app/src/infrastructure/mongodb.js @@ -100,11 +100,9 @@ async function setupDb() { db.systemmessages = internalDb.collection('systemmessages') db.tags = internalDb.collection('tags') db.teamInvites = internalDb.collection('teamInvites') - db.templates = internalDb.collection('templates') db.tokens = internalDb.collection('tokens') db.userAuditLogEntries = internalDb.collection('userAuditLogEntries') db.users = internalDb.collection('users') - db.userstubs = internalDb.collection('userstubs') db.onboardingDataCollection = internalDb.collection( 'onboardingDataCollection' ) diff --git a/services/web/migrations/20190912145030_create_templates_indexes.mjs b/services/web/migrations/20190912145030_create_templates_indexes.mjs index ed7ddce90d..ceaf176e6b 100644 --- a/services/web/migrations/20190912145030_create_templates_indexes.mjs +++ b/services/web/migrations/20190912145030_create_templates_indexes.mjs @@ -1,6 +1,8 @@ /* eslint-disable no-unused-vars */ import Helpers from './lib/helpers.mjs' +import mongodb from '../app/src/infrastructure/mongodb.js' +const { getCollectionInternal } = mongodb const tags = ['server-pro', 'saas'] @@ -26,17 +28,21 @@ const indexes = [ }, ] -const migrate = async client => { - const { db } = client +async function getCollection() { + // NOTE: This is a stale collection, it will get dropped in a later migration. + return await getCollectionInternal('templates') +} - await Helpers.addIndexesToCollection(db.templates, indexes) +const migrate = async client => { + const collection = await getCollection() + await Helpers.addIndexesToCollection(collection, indexes) } const rollback = async client => { - const { db } = client + const collection = await getCollection() try { - await Helpers.dropIndexesFromCollection(db.templates, indexes) + await Helpers.dropIndexesFromCollection(collection, indexes) } catch (err) { console.error('Something went wrong rolling back the migrations', err) } diff --git a/services/web/migrations/20190912145033_create_userstubs_indexes.mjs b/services/web/migrations/20190912145033_create_userstubs_indexes.mjs index 28af185ac3..35f6796387 100644 --- a/services/web/migrations/20190912145033_create_userstubs_indexes.mjs +++ b/services/web/migrations/20190912145033_create_userstubs_indexes.mjs @@ -1,6 +1,8 @@ /* eslint-disable no-unused-vars */ import Helpers from './lib/helpers.mjs' +import mongodb from '../app/src/infrastructure/mongodb.js' +const { getCollectionInternal } = mongodb const tags = ['saas'] @@ -13,17 +15,22 @@ const indexes = [ }, ] -const migrate = async client => { - const { db } = client +async function getCollection() { + // NOTE: This is a stale collection, it will get dropped in a later migration. + return await getCollectionInternal('userstubs') +} - await Helpers.addIndexesToCollection(db.userstubs, indexes) +const migrate = async client => { + const collection = await getCollection() + + await Helpers.addIndexesToCollection(collection, indexes) } const rollback = async client => { - const { db } = client + const collection = await getCollection() try { - await Helpers.dropIndexesFromCollection(db.userstubs, indexes) + await Helpers.dropIndexesFromCollection(collection, indexes) } catch (err) { console.error('Something went wrong rolling back the migrations', err) } diff --git a/services/web/migrations/20241002180623_drop_unused_collections.mjs b/services/web/migrations/20241002180623_drop_unused_collections.mjs new file mode 100644 index 0000000000..c80cee8bcc --- /dev/null +++ b/services/web/migrations/20241002180623_drop_unused_collections.mjs @@ -0,0 +1,31 @@ +import Helpers from './lib/helpers.mjs' + +const tags = ['saas'] + +const unusedCollections = [ + 'githubBuilds', + 'githubRepos', + 'userstubs', + 'templates', + 'quotes', + 'folders', + 'files', + 'objectlabs-system', + 'objectlabs-system.admin.collections', +] + +const migrate = async client => { + for (const name of unusedCollections) { + await Helpers.dropCollection(name) + } +} + +const rollback = async client => { + // can't really do anything here +} + +export default { + tags, + migrate, + rollback, +}