From bc31247d249d3e8bc3574279df32b43b438f9006 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 17 Jun 2022 14:34:10 +0100 Subject: [PATCH] Merge pull request #8471 from overleaf/bg-ignore-upgradefailed-when-history-does-not-exist [scripts] allow history upgrade in failure case GitOrigin-RevId: 7c789968bd74719e3a0232422094ae3e9231a044 --- ..._v1_without_conversion_if_no_sl_history.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js b/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js index 8379adc762..a9c5c7ccd3 100644 --- a/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js +++ b/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js @@ -4,6 +4,8 @@ const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10 const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 100 const DRY_RUN = process.env.DRY_RUN !== 'false' const USE_QUERY_HINT = process.env.USE_QUERY_HINT !== 'false' +const UPGRADE_FAILED_WITH_EMPTY_HISTORY = + process.env.UPGRADE_FAILED_WITH_EMPTY_HISTORY === 'true' // persist fallback in order to keep batchedUpdate in-sync process.env.BATCH_SIZE = BATCH_SIZE // raise mongo timeout to 1hr if otherwise unspecified @@ -21,6 +23,7 @@ console.log({ WRITE_CONCURRENCY, BATCH_SIZE, USE_QUERY_HINT, + UPGRADE_FAILED_WITH_EMPTY_HISTORY, }) const RESULT = { @@ -34,23 +37,30 @@ async function processBatch(_, projects) { } async function processProject(project) { - // safety check + // safety check if history exists and there was a failed upgrade + const anyDocHistory = await anyDocHistoryExists(project) + const anyDocHistoryIndex = await anyDocHistoryIndexExists(project) if ( project.overleaf && project.overleaf.history && project.overleaf.history.upgradeFailed ) { - // a failed history upgrade might look like a v1 project, but history may be broken - return + const emptyHistory = !anyDocHistory && !anyDocHistoryIndex + if (emptyHistory && UPGRADE_FAILED_WITH_EMPTY_HISTORY) { + console.log( + `upgrading previously failed project ${project._id} with empty history` + ) + } else { + // a failed history upgrade might look like a v1 project, but history may be broken + return + } } const preserveHistory = await shouldPreserveHistory(project) if (preserveHistory) { // if we need to preserve history, then we must bail out if history exists - const anyDocHistory = await anyDocHistoryExists(project) if (anyDocHistory) { return } - const anyDocHistoryIndex = await anyDocHistoryIndexExists(project) if (anyDocHistoryIndex) { return }