overleaf/services/web/migrations/lib/helpers.js
Shane Kilkelly 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations
Migrations: tag migrations with relevant environment
GitOrigin-RevId: ad6c3bea19d3c21a1fdae58e09c861a3173c792b
2021-07-28 02:05:49 +00:00

26 lines
723 B
JavaScript

const { getCollectionNames } = 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(db, collectionName) {
const allCollections = await getCollectionNames()
if (!allCollections.includes(collectionName)) return
return db[collectionName].drop()
}
module.exports = {
addIndexesToCollection,
dropIndexesFromCollection,
dropCollection,
}