migrate_ranges_support.mjs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import HistoryRangesSupportMigration from '../../app/src/Features/History/HistoryRangesSupportMigration.mjs'
  2. import minimist from 'minimist'
  3. import { scriptRunner } from '../lib/ScriptRunner.mjs'
  4. async function main() {
  5. const {
  6. projectIds,
  7. ownerIds,
  8. minId,
  9. maxId,
  10. maxCount,
  11. direction,
  12. force,
  13. stopOnError,
  14. quickOnly,
  15. concurrency,
  16. } = parseArgs()
  17. await HistoryRangesSupportMigration.promises.migrateProjects({
  18. projectIds,
  19. ownerIds,
  20. minId,
  21. maxId,
  22. maxCount,
  23. direction,
  24. force,
  25. stopOnError,
  26. quickOnly,
  27. concurrency,
  28. })
  29. }
  30. function usage() {
  31. console.error(`Usage: migrate_ranges_support.mjs [OPTIONS]
  32. Options:
  33. --help Print this help
  34. --owner-id Migrate all projects owned by this owner
  35. --project-id Migrate this project
  36. --min-id Migrate projects from this id
  37. --max-id Migrate projects to this id
  38. --max-count Migrate at most this number of projects
  39. --all Migrate all projects
  40. --backwards Disable history ranges support for selected project ids
  41. --force Migrate projects even if they were already migrated
  42. --stop-on-error Stop after first migration error
  43. --quick-only Do not try a resync migration if quick migration fails
  44. --concurrency How many jobs to run in parallel
  45. `)
  46. }
  47. function parseArgs() {
  48. const args = minimist(process.argv.slice(2), {
  49. boolean: ['backwards', 'help', 'all', 'force', 'quick-only'],
  50. string: ['owner-id', 'project-id', 'min-id', 'max-id'],
  51. })
  52. if (args.help) {
  53. usage()
  54. process.exit(0)
  55. }
  56. const direction = args.backwards ? 'backwards' : 'forwards'
  57. const ownerIds = arrayOpt(args['owner-id'])
  58. const projectIds = arrayOpt(args['project-id'])
  59. const minId = args['min-id']
  60. const maxId = args['max-id']
  61. const maxCount = args['max-count']
  62. const force = args.force
  63. const stopOnError = args['stop-on-error']
  64. const quickOnly = args['quick-only']
  65. const concurrency = args.concurrency ?? 1
  66. const all = args.all
  67. if (
  68. !all &&
  69. ownerIds == null &&
  70. projectIds == null &&
  71. minId == null &&
  72. maxId == null &&
  73. maxCount == null
  74. ) {
  75. console.error(
  76. 'Please specify at least one filter, or --all to process all projects\n'
  77. )
  78. usage()
  79. process.exit(1)
  80. }
  81. return {
  82. ownerIds,
  83. projectIds,
  84. minId,
  85. maxId,
  86. maxCount,
  87. direction,
  88. force,
  89. stopOnError,
  90. quickOnly,
  91. concurrency,
  92. }
  93. }
  94. function arrayOpt(value) {
  95. if (typeof value === 'string') {
  96. return [value]
  97. } else if (Array.isArray(value)) {
  98. return value
  99. } else {
  100. return undefined
  101. }
  102. }
  103. try {
  104. await scriptRunner(main)
  105. process.exit(0)
  106. } catch (error) {
  107. console.error(error)
  108. process.exit(1)
  109. }