migrate_ranges_support.js 2.8 KB

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