Просмотр исходного кода

Merge pull request #20770 from overleaf/ls-drop-unused-collections

drop unused collections

GitOrigin-RevId: 4b079f15dca349ef6a5aed8d9dcb35478819c2ce
Liangjun Song 2 лет назад
Родитель
Сommit
7258ddcf02

+ 0 - 2
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'
   )

+ 11 - 5
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)
   }

+ 11 - 4
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 = [
   },
 ]
 
+async function getCollection() {
+  // NOTE: This is a stale collection, it will get dropped in a later migration.
+  return await getCollectionInternal('userstubs')
+}
+
 const migrate = async client => {
-  const { db } = client
+  const collection = await getCollection()
 
-  await Helpers.addIndexesToCollection(db.userstubs, indexes)
+  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)
   }

+ 31 - 0
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,
+}