mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #15711 from overleaf/em-migrate-docops-versions
Migrate doc versions from docOps to docs GitOrigin-RevId: f1d7f68e0e5e869c431c4479766b81c9df355be5
This commit is contained in:
parent
3e5273144e
commit
9e090992f1
1 changed files with 33 additions and 0 deletions
|
@ -0,0 +1,33 @@
|
|||
const { ReadPreference } = require('mongodb')
|
||||
|
||||
exports.tags = ['server-ce', 'server-pro', 'saas']
|
||||
|
||||
exports.migrate = async ({ db }) => {
|
||||
const records = db.docOps.find(
|
||||
{},
|
||||
{ readPreference: ReadPreference.secondaryPreferred }
|
||||
)
|
||||
|
||||
let docsProcessed = 0
|
||||
for await (const record of records) {
|
||||
const docId = record.doc_id
|
||||
const version = record.version
|
||||
await db.docs.updateOne(
|
||||
{
|
||||
_id: docId,
|
||||
version: { $exists: false },
|
||||
},
|
||||
{ $set: { version } }
|
||||
)
|
||||
docsProcessed += 1
|
||||
if (docsProcessed % 100000 === 0) {
|
||||
console.log(`${docsProcessed} docs processed`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.rollback = async ({ db }) => {
|
||||
// Nothing to do on rollback. We don't want to remove versions from the docs
|
||||
// collection because they might be more current than the ones in the docOps
|
||||
// collection.
|
||||
}
|
Loading…
Reference in a new issue