migrate_ranges_support.mjs 2.7 KB

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