migrate_ranges_support.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. } = parseArgs()
  16. await HistoryRangesSupportMigration.promises.migrateProjects({
  17. projectIds,
  18. ownerIds,
  19. minId,
  20. maxId,
  21. maxCount,
  22. direction,
  23. force,
  24. stopOnError,
  25. })
  26. }
  27. function usage() {
  28. console.error(`Usage: migrate_ranges_support.js [OPTIONS]
  29. Options:
  30. --help Print this help
  31. --owner-id Migrate all projects owned by this owner
  32. --project-id Migrate this project
  33. --min-id Migrate projects from this id
  34. --max-id Migrate projects to this id
  35. --max-count Migrate at most this number of projects
  36. --all Migrate all projects
  37. --backwards Disable history ranges support for selected project ids
  38. --force Migrate projects even if they were already migrated
  39. --stop-on-error Stop after first migration error
  40. `)
  41. }
  42. function parseArgs() {
  43. const args = minimist(process.argv.slice(2), {
  44. boolean: ['backwards', 'help', 'all', 'force'],
  45. string: ['owner-id', 'project-id', 'min-id', 'max-id'],
  46. })
  47. if (args.help) {
  48. usage()
  49. process.exit(0)
  50. }
  51. const direction = args.backwards ? 'backwards' : 'forwards'
  52. const ownerIds = arrayOpt(args['owner-id'])
  53. const projectIds = arrayOpt(args['project-id'])
  54. const minId = args['min-id']
  55. const maxId = args['max-id']
  56. const maxCount = args['max-count']
  57. const force = args.force
  58. const stopOnError = args['stop-on-error']
  59. const all = args.all
  60. if (
  61. !all &&
  62. ownerIds == null &&
  63. projectIds == null &&
  64. minId == null &&
  65. maxId == null &&
  66. maxCount == null
  67. ) {
  68. console.error(
  69. 'Please specify at least one filter, or --all to process all projects\n'
  70. )
  71. usage()
  72. process.exit(1)
  73. }
  74. return {
  75. ownerIds,
  76. projectIds,
  77. minId,
  78. maxId,
  79. maxCount,
  80. direction,
  81. force,
  82. stopOnError,
  83. }
  84. }
  85. function arrayOpt(value) {
  86. if (typeof value === 'string') {
  87. return [value]
  88. } else if (Array.isArray(value)) {
  89. return value
  90. } else {
  91. return undefined
  92. }
  93. }
  94. main()
  95. .then(() => {
  96. process.exit(0)
  97. })
  98. .catch(err => {
  99. console.error(err)
  100. process.exit(1)
  101. })