From 56b57fb9d7a77b97b8d9ae60f7bfbea0710a1abf Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Tue, 7 Feb 2023 10:15:01 +0100 Subject: [PATCH] Merge pull request #11663 from overleaf/bg-add-migration-force-options add migration force options GitOrigin-RevId: 51eb88e995a6e348e00208e9d01c9c1fa6c0c1ea --- .../app/src/HistoryUpgradeHelper.js | 4 ++-- .../web/scripts/history/migrate_history.js | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/services/web/modules/history-migration/app/src/HistoryUpgradeHelper.js b/services/web/modules/history-migration/app/src/HistoryUpgradeHelper.js index 3e065c089d..70dc14ca1c 100644 --- a/services/web/modules/history-migration/app/src/HistoryUpgradeHelper.js +++ b/services/web/modules/history-migration/app/src/HistoryUpgradeHelper.js @@ -98,7 +98,7 @@ async function determineProjectHistoryType(project) { } } -async function upgradeProject(project) { +async function upgradeProject(project, options) { const historyType = await determineProjectHistoryType(project) if (historyType === 'V2') { return { historyType, upgraded: true } @@ -107,7 +107,7 @@ async function upgradeProject(project) { if (!upgradeFn) { return { error: 'unsupported history type' } } - const result = await upgradeFn(project) + const result = await upgradeFn(project, options) result.historyType = historyType return result } diff --git a/services/web/scripts/history/migrate_history.js b/services/web/scripts/history/migrate_history.js index 9e35912165..f616b5e147 100644 --- a/services/web/scripts/history/migrate_history.js +++ b/services/web/scripts/history/migrate_history.js @@ -1,6 +1,8 @@ // raise mongo timeout to 1hr if otherwise unspecified process.env.MONGO_SOCKET_TIMEOUT = parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 3600000 + +const VERSION = '0.9.0-cli' const { countProjects, countDocHistory, @@ -24,12 +26,16 @@ const DEFAULT_OUTPUT_FILE = `history-migration-${new Date() const argv = minimist(process.argv.slice(2), { boolean: [ 'verbose', + 'fix-invalid-characters', + 'convert-large-docs-to-file', + 'import-broken-history-as-zip', + 'force-upgrade-on-failure', 'dry-run', 'use-query-hint', 'retry-failed', 'archive-on-failure', ], - string: ['output'], + string: ['output', 'user-id'], alias: { verbose: 'v', output: 'o', @@ -153,13 +159,23 @@ async function migrateProjects(projectsToMigrate) { ) }, 500) + const options = { + migrationOptions: { + archiveOnFailure: argv['import-broken-history-as-zip'], + fixInvalidCharacters: argv['fix-invalid-characters'], + forceNewHistoryOnFailure: argv['force-upgrade-on-failure'], + }, + convertLargeDocsToFile: argv['convert-large-docs-to-file'], + userId: argv['user-id'], + reason: VERSION, + } async function _migrateProject(project) { if (INTERRUPT) { return // don't start any new jobs if we're shutting down } const startTime = new Date() try { - const result = await upgradeProject(project._id) + const result = await upgradeProject(project._id, options) i++ if (INTERRUPT && limit.activeCount > 1) { // an interrupt was requested while this job was running