Merge pull request #13284 from overleaf/msm-fix-history-force-clean

[web] Fix `--force-clean` for history migration

GitOrigin-RevId: 747154e8de3c64b79af8705b7f6155b966d6fa71
This commit is contained in:
Miguel Serrano 2023-06-01 11:41:57 +02:00 committed by Copybot
parent 5fbd5e21a2
commit ae35d880ee
2 changed files with 12 additions and 3 deletions

View file

@ -115,6 +115,11 @@ async function upgradeProject(project, options) {
const projectId = project._id const projectId = project._id
// delete any existing history stored in the mongo backend // delete any existing history stored in the mongo backend
await HistoryManager.promises.deleteProject(projectId, projectId) await HistoryManager.promises.deleteProject(projectId, projectId)
// unset overleaf.history.id to prevent the migration script from failing on checks
await db.projects.updateOne(
{ _id: projectId },
{ $unset: { 'overleaf.history.id': '' } }
)
} catch (err) { } catch (err) {
// failed to delete existing history, but we can try to continue // failed to delete existing history, but we can try to continue
} }

View file

@ -147,7 +147,7 @@ async function migrateProjects(projectsToMigrate) {
} }
// send log output for each migration to a file // send log output for each migration to a file
const output = fs.createWriteStream(argv.output, { flags: 'a' }) const output = fs.createWriteStream(argv.output, { flags: 'a' })
console.log(`Writing log output to ${argv.output}`) console.log(`Writing log output to ${process.cwd()}/${argv.output}`)
const logger = new console.Console({ stdout: output }) const logger = new console.Console({ stdout: output })
function logJson(obj) { function logJson(obj) {
logger.log(JSON.stringify(obj)) logger.log(JSON.stringify(obj))
@ -253,8 +253,12 @@ async function main() {
console.log('Projects migrated: ', projectsMigrated) console.log('Projects migrated: ', projectsMigrated)
console.log('Projects failed: ', projectsFailed) console.log('Projects failed: ', projectsFailed)
if (projectsFailed > 0) { if (projectsFailed > 0) {
console.log(`Log output written to ${argv.output}`) console.log('------------------------------------------------------')
console.log('Please check the log for errors.') console.log(`Log output written to ${process.cwd()}/${argv.output}`)
console.log(
'Please check the log for errors. Attach the content of the file when contacting support.'
)
console.log('------------------------------------------------------')
} }
if (INTERRUPT) { if (INTERRUPT) {
console.log('Migration interrupted, please run again to continue.') console.log('Migration interrupted, please run again to continue.')