2024-10-22 04:21:39 -04:00
|
|
|
import HistoryRangesSupportMigration from '../../app/src/Features/History/HistoryRangesSupportMigration.mjs'
|
|
|
|
import { waitForDb } from '../../app/src/infrastructure/mongodb.js'
|
|
|
|
import minimist from 'minimist'
|
2024-06-18 10:00:00 -04:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await waitForDb()
|
2024-06-19 10:52:52 -04:00
|
|
|
const {
|
|
|
|
projectIds,
|
|
|
|
ownerIds,
|
|
|
|
minId,
|
|
|
|
maxId,
|
|
|
|
maxCount,
|
|
|
|
direction,
|
|
|
|
force,
|
|
|
|
stopOnError,
|
2024-07-02 11:07:12 -04:00
|
|
|
quickOnly,
|
2024-07-05 08:16:31 -04:00
|
|
|
concurrency,
|
2024-06-19 10:52:52 -04:00
|
|
|
} = parseArgs()
|
|
|
|
await HistoryRangesSupportMigration.promises.migrateProjects({
|
|
|
|
projectIds,
|
|
|
|
ownerIds,
|
|
|
|
minId,
|
|
|
|
maxId,
|
|
|
|
maxCount,
|
|
|
|
direction,
|
|
|
|
force,
|
|
|
|
stopOnError,
|
2024-07-02 11:07:12 -04:00
|
|
|
quickOnly,
|
2024-07-05 08:16:31 -04:00
|
|
|
concurrency,
|
2024-06-19 10:52:52 -04:00
|
|
|
})
|
2024-06-18 10:00:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
2024-10-22 04:21:39 -04:00
|
|
|
console.error(`Usage: migrate_ranges_support.mjs [OPTIONS]
|
2024-06-19 10:52:52 -04:00
|
|
|
|
|
|
|
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
|
2024-07-02 11:07:12 -04:00
|
|
|
--quick-only Do not try a resync migration if quick migration fails
|
2024-07-05 08:16:31 -04:00
|
|
|
--concurrency How many jobs to run in parallel
|
2024-06-19 10:52:52 -04:00
|
|
|
`)
|
2024-06-18 10:00:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseArgs() {
|
|
|
|
const args = minimist(process.argv.slice(2), {
|
2024-07-02 11:07:12 -04:00
|
|
|
boolean: ['backwards', 'help', 'all', 'force', 'quick-only'],
|
2024-06-19 10:52:52 -04:00
|
|
|
string: ['owner-id', 'project-id', 'min-id', 'max-id'],
|
2024-06-18 10:00:00 -04:00
|
|
|
})
|
|
|
|
|
2024-06-19 10:52:52 -04:00
|
|
|
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']
|
2024-07-02 11:07:12 -04:00
|
|
|
const quickOnly = args['quick-only']
|
2024-07-05 08:16:31 -04:00
|
|
|
const concurrency = args.concurrency ?? 1
|
2024-06-19 10:52:52 -04:00
|
|
|
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'
|
|
|
|
)
|
2024-06-18 10:00:00 -04:00
|
|
|
usage()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2024-06-19 10:52:52 -04:00
|
|
|
ownerIds,
|
|
|
|
projectIds,
|
|
|
|
minId,
|
|
|
|
maxId,
|
|
|
|
maxCount,
|
|
|
|
direction,
|
|
|
|
force,
|
|
|
|
stopOnError,
|
2024-07-02 11:07:12 -04:00
|
|
|
quickOnly,
|
2024-07-05 08:16:31 -04:00
|
|
|
concurrency,
|
2024-06-19 10:52:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function arrayOpt(value) {
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
return [value]
|
|
|
|
} else if (Array.isArray(value)) {
|
|
|
|
return value
|
|
|
|
} else {
|
|
|
|
return undefined
|
2024-06-18 10:00:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-22 04:21:39 -04:00
|
|
|
try {
|
|
|
|
await main()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|