pr_27932.patch 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. diff --git a/services/history-v1/storage/scripts/back_fill_file_hash.mjs b/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  2. index 33962c5da7d4..8b25fb8bd603 100644
  3. --- a/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  4. +++ b/services/history-v1/storage/scripts/back_fill_file_hash.mjs
  5. @@ -78,11 +78,29 @@ ObjectId.cacheHexString = true
  6. * @property {Blob} [blob]
  7. */
  8. +/**
  9. + * Start and end for range.
  10. + * @type {Date}
  11. + */
  12. +const PUBLIC_LAUNCH_DATE = new Date('2012-01-01T00:00:00Z')
  13. +const DEFAULT_BATCH_RANGE_START_DATE = PUBLIC_LAUNCH_DATE
  14. +const DEFAULT_BATCH_RANGE_END_DATE = new Date()
  15. +
  16. +function usesDefaultBatchRange() {
  17. + return (
  18. + BATCH_RANGE_START ===
  19. + objectIdFromInput(
  20. + DEFAULT_BATCH_RANGE_START_DATE.toISOString()
  21. + ).toString() &&
  22. + BATCH_RANGE_END ===
  23. + objectIdFromInput(DEFAULT_BATCH_RANGE_END_DATE.toISOString()).toString()
  24. + )
  25. +}
  26. +
  27. /**
  28. * @return {{PROJECT_IDS_FROM: string, PROCESS_HASHED_FILES: boolean, LOGGING_IDENTIFIER: string, BATCH_RANGE_START: string, BATCH_RANGE_END: string, PROCESS_NON_DELETED_PROJECTS: boolean, PROCESS_DELETED_PROJECTS: boolean, PROCESS_BLOBS: boolean, DRY_RUN: boolean, OUTPUT_FILE: string, DISPLAY_REPORT: boolean, CONCURRENCY: number, CONCURRENT_BATCHES: number, RETRIES: number, RETRY_DELAY_MS: number, RETRY_FILESTORE_404: boolean, BUFFER_DIR_PREFIX: string, STREAM_HIGH_WATER_MARK: number, LOGGING_INTERVAL: number, SLEEP_BEFORE_EXIT: number }}
  29. */
  30. function parseArgs() {
  31. - const PUBLIC_LAUNCH_DATE = new Date('2012-01-01T00:00:00Z')
  32. const DEFAULT_OUTPUT_FILE = `/var/log/overleaf/file-migration-${new Date()
  33. .toISOString()
  34. .replace(/[:.]/g, '_')}.log`
  35. @@ -1475,6 +1493,49 @@ try {
  36. )
  37. code++
  38. }
  39. + console.warn('-'.repeat(79))
  40. + if (code === 0) {
  41. + const allProcessed =
  42. + !DRY_RUN &&
  43. + PROCESS_NON_DELETED_PROJECTS &&
  44. + PROCESS_DELETED_PROJECTS &&
  45. + PROCESS_HASHED_FILES &&
  46. + !PROJECT_IDS_FROM &&
  47. + usesDefaultBatchRange()
  48. + if (allProcessed) {
  49. + await db
  50. + .collection('migrations')
  51. + .updateOne(
  52. + { name: '20250519101128_binary_files_migration' },
  53. + { $set: { migratedAt: new Date(DEFAULT_BATCH_RANGE_END_DATE) } },
  54. + { upsert: true }
  55. + )
  56. + console.warn('The binary files migration succeeded.')
  57. + console.warn(
  58. + 'You can now proceed to OVERLEAF_FILESTORE_MIGRATION_LEVEL=2.'
  59. + )
  60. + } else {
  61. + console.warn(
  62. + 'The binary files migration succeeded on a subset of files (at least one of --dry-run, --skip-hashed-files, --from-file, --BATCH_RANGE_START or --BATCH_RANGE_END is set and --all is not set).'
  63. + )
  64. + console.warn(
  65. + 'Once you are done with all the partial runs, you need to run the migration again on all projects/files to ensure that all files are migrated into the full project history system.'
  66. + )
  67. + console.warn('The full run will unlock the upgrade to Server Pro 6.0.')
  68. + }
  69. + } else {
  70. + console.warn('The binary files migration failed, see above.')
  71. + console.warn(
  72. + 'Please review the failures and check the docs on remediating the failures.'
  73. + )
  74. + console.warn(
  75. + 'Docs: https://docs.overleaf.com/on-premises/release-notes/release-notes-5.x.x/binary-files-migration#troubleshooting'
  76. + )
  77. + console.warn(
  78. + 'In case there is not solution available, please reach out to support as detailed in the docs.'
  79. + )
  80. + }
  81. + console.warn('-'.repeat(79))
  82. await setTimeout(SLEEP_BEFORE_EXIT)
  83. process.exit(code)
  84. } catch (err) {