overleaf/services/web/scripts/history/migrate_ranges_support.js
Eric Mc Sween fbdf245517 Merge pull request #19273 from overleaf/em-history-migration-concurrency
Add concurrency option to history ranges support migration script

GitOrigin-RevId: 8707abc9b76116090332b6abb11030adb17ceb4e
2024-07-15 09:00:46 +00:00

122 lines
2.8 KiB
JavaScript

const HistoryRangesSupportMigration = require('../../app/src/Features/History/HistoryRangesSupportMigration')
const { waitForDb } = require('../../app/src/infrastructure/mongodb')
const minimist = require('minimist')
async function main() {
await waitForDb()
const {
projectIds,
ownerIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
} = parseArgs()
await HistoryRangesSupportMigration.promises.migrateProjects({
projectIds,
ownerIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
})
}
function usage() {
console.error(`Usage: migrate_ranges_support.js [OPTIONS]
Options:
--help Print this help
--owner-id Migrate all projects owned by this owner
--project-id Migrate this project
--min-id Migrate projects from this id
--max-id Migrate projects to this id
--max-count Migrate at most this number of projects
--all Migrate all projects
--backwards Disable history ranges support for selected project ids
--force Migrate projects even if they were already migrated
--stop-on-error Stop after first migration error
--quick-only Do not try a resync migration if quick migration fails
--concurrency How many jobs to run in parallel
`)
}
function parseArgs() {
const args = minimist(process.argv.slice(2), {
boolean: ['backwards', 'help', 'all', 'force', 'quick-only'],
string: ['owner-id', 'project-id', 'min-id', 'max-id'],
})
if (args.help) {
usage()
process.exit(0)
}
const direction = args.backwards ? 'backwards' : 'forwards'
const ownerIds = arrayOpt(args['owner-id'])
const projectIds = arrayOpt(args['project-id'])
const minId = args['min-id']
const maxId = args['max-id']
const maxCount = args['max-count']
const force = args.force
const stopOnError = args['stop-on-error']
const quickOnly = args['quick-only']
const concurrency = args.concurrency ?? 1
const all = args.all
if (
!all &&
ownerIds == null &&
projectIds == null &&
minId == null &&
maxId == null &&
maxCount == null
) {
console.error(
'Please specify at least one filter, or --all to process all projects\n'
)
usage()
process.exit(1)
}
return {
ownerIds,
projectIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
}
}
function arrayOpt(value) {
if (typeof value === 'string') {
return [value]
} else if (Array.isArray(value)) {
return value
} else {
return undefined
}
}
main()
.then(() => {
process.exit(0)
})
.catch(err => {
console.error(err)
process.exit(1)
})