From baa2d08b7f31a99dad7ad162092b91335c067403 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 9 Jun 2022 11:01:44 +0100 Subject: [PATCH] Merge pull request #8340 from overleaf/bg-one-shot-migration-script [web] allow running history conversion script on single project GitOrigin-RevId: 038005605a048d97d3fabcfa16b1c2421094e2e5 --- ...rade_none_with_conversion_if_sl_history.js | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js b/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js index cdd2d08625..206bd5eb95 100644 --- a/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js +++ b/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js @@ -14,8 +14,10 @@ process.env.BATCH_SIZE = BATCH_SIZE process.env.MONGO_SOCKET_TIMEOUT = parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 3600000 -const { ReadPreference } = require('mongodb') -const { db } = require('../../app/src/infrastructure/mongodb') +const PROJECT_ID = process.env.PROJECT_ID + +const { ObjectId, ReadPreference } = require('mongodb') +const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') const { promiseMapWithLimit } = require('../../app/src/util/promises') const { batchedUpdate } = require('../helpers/batchedUpdate') const ProjectHistoryController = require('../../modules/admin-panel/app/src/ProjectHistoryController') @@ -29,6 +31,7 @@ console.log({ MAX_FAILURES, USE_QUERY_HINT, RETRY_FAILED, + PROJECT_ID, }) const RESULT = { @@ -167,25 +170,31 @@ async function anyDocHistoryIndexExists(project) { } async function main() { - const projection = { - _id: 1, - overleaf: 1, + if (PROJECT_ID) { + await waitForDb() + const project = await db.projects.findOne({ _id: ObjectId(PROJECT_ID) }) + await processProject(project) + } else { + const projection = { + _id: 1, + overleaf: 1, + } + const options = {} + if (USE_QUERY_HINT) { + options.hint = { _id: 1 } + } + await batchedUpdate( + 'projects', + // we originally used + // 'overleaf.history.id': { $exists: false } + // but display false is indexed and contains all the above, + // it can be faster to skip projects with a history ID than to use a query + { 'overleaf.history.display': { $ne: true } }, + processBatch, + projection, + options + ) } - const options = {} - if (USE_QUERY_HINT) { - options.hint = { _id: 1 } - } - await batchedUpdate( - 'projects', - // we originally used - // 'overleaf.history.id': { $exists: false } - // but display false is indexed and contains all the above, - // it can be faster to skip projects with a history ID than to use a query - { 'overleaf.history.display': { $ne: true } }, - processBatch, - projection, - options - ) console.log('Final') console.log(RESULT) }