Merge pull request #16446 from overleaf/em-docops-migration-min-id

Support min id in docOps migration

GitOrigin-RevId: d08887aca1e8b744515d42e0b6f2286d45c4d93e
This commit is contained in:
Eric Mc Sween 2024-01-10 07:32:04 -05:00 committed by Copybot
parent 5aeb1f1459
commit a9d87232ca

View file

@ -1,14 +1,18 @@
const { ReadPreference } = require('mongodb')
const { ObjectId, ReadPreference } = require('mongodb')
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '1000', 10)
const MIN_ID = process.env.MIN_ID
exports.tags = ['server-ce', 'server-pro', 'saas']
exports.migrate = async ({ db }) => {
const records = db.docOps.find(
{},
{ readPreference: ReadPreference.secondaryPreferred }
)
const filter = {}
if (MIN_ID) {
filter._id = { $gte: new ObjectId(MIN_ID) }
}
const records = db.docOps
.find(filter, { readPreference: ReadPreference.secondaryPreferred })
.sort({ _id: 1 })
let docsProcessed = 0
let batch = []
@ -30,12 +34,13 @@ exports.migrate = async ({ db }) => {
}
docsProcessed += 1
if (docsProcessed % 100000 === 0) {
console.log(`${docsProcessed} docs processed`)
console.log(`${docsProcessed} docs processed - last id: ${docId}`)
}
}
if (batch.length > 0) {
await db.docs.bulkWrite(batch, { ordered: false })
}
console.log(`DONE - ${docsProcessed} docs processed`)
}
exports.rollback = async ({ db }) => {