migrate_ranges_support.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. } = 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. })
  28. }
  29. function usage() {
  30. console.error(`Usage: migrate_ranges_support.js [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. `)
  44. }
  45. function parseArgs() {
  46. const args = minimist(process.argv.slice(2), {
  47. boolean: ['backwards', 'help', 'all', 'force', 'quick-only'],
  48. string: ['owner-id', 'project-id', 'min-id', 'max-id'],
  49. })
  50. if (args.help) {
  51. usage()
  52. process.exit(0)
  53. }
  54. const direction = args.backwards ? 'backwards' : 'forwards'
  55. const ownerIds = arrayOpt(args['owner-id'])
  56. const projectIds = arrayOpt(args['project-id'])
  57. const minId = args['min-id']
  58. const maxId = args['max-id']
  59. const maxCount = args['max-count']
  60. const force = args.force
  61. const stopOnError = args['stop-on-error']
  62. const quickOnly = args['quick-only']
  63. const all = args.all
  64. if (
  65. !all &&
  66. ownerIds == null &&
  67. projectIds == null &&
  68. minId == null &&
  69. maxId == null &&
  70. maxCount == null
  71. ) {
  72. console.error(
  73. 'Please specify at least one filter, or --all to process all projects\n'
  74. )
  75. usage()
  76. process.exit(1)
  77. }
  78. return {
  79. ownerIds,
  80. projectIds,
  81. minId,
  82. maxId,
  83. maxCount,
  84. direction,
  85. force,
  86. stopOnError,
  87. quickOnly,
  88. }
  89. }
  90. function arrayOpt(value) {
  91. if (typeof value === 'string') {
  92. return [value]
  93. } else if (Array.isArray(value)) {
  94. return value
  95. } else {
  96. return undefined
  97. }
  98. }
  99. main()
  100. .then(() => {
  101. process.exit(0)
  102. })
  103. .catch(err => {
  104. console.error(err)
  105. process.exit(1)
  106. })