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

drop unused collections

GitOrigin-RevId: 4b079f15dca349ef6a5aed8d9dcb35478819c2ce
This commit is contained in:
Liangjun Song 2024-10-07 18:20:36 +08:00 committed by Copybot
parent ee8c13ec7e
commit 7258ddcf02
4 changed files with 54 additions and 12 deletions

View file

@ -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'
)

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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,
}