mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 07:15:25 -05:00
eef5cd00e3
[migrations] delete unused collections and properly apply saml indexes GitOrigin-RevId: eafcde98cbb603c275986a5bca708b9f8221877f
37 lines
955 B
JavaScript
37 lines
955 B
JavaScript
const {
|
|
db,
|
|
getCollectionNames,
|
|
getCollectionInternal,
|
|
waitForDb,
|
|
} = require('../../app/src/infrastructure/mongodb')
|
|
|
|
async function addIndexesToCollection(collection, indexes) {
|
|
return Promise.all(
|
|
indexes.map(index => {
|
|
index.background = true
|
|
return collection.createIndex(index.key, index)
|
|
})
|
|
)
|
|
}
|
|
|
|
async function dropIndexesFromCollection(collection, indexes) {
|
|
return Promise.all(indexes.map(index => collection.dropIndex(index.name)))
|
|
}
|
|
|
|
async function dropCollection(collectionName) {
|
|
await waitForDb()
|
|
if (db[collectionName]) {
|
|
throw new Error(`blocking drop of an active collection: ${collectionName}`)
|
|
}
|
|
|
|
const allCollections = await getCollectionNames()
|
|
if (!allCollections.includes(collectionName)) return
|
|
const collection = await getCollectionInternal(collectionName)
|
|
await collection.drop()
|
|
}
|
|
|
|
module.exports = {
|
|
addIndexesToCollection,
|
|
dropIndexesFromCollection,
|
|
dropCollection,
|
|
}
|