unset_allow_downgrade.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 100
  2. // persist fallback in order to keep batchedUpdate in-sync
  3. process.env.BATCH_SIZE = BATCH_SIZE
  4. const PROJECT_ID = process.env.PROJECT_ID
  5. const {
  6. db,
  7. waitForDb,
  8. ObjectId,
  9. } = require('../../app/src/infrastructure/mongodb')
  10. const { batchedUpdate } = require('../helpers/batchedUpdate')
  11. console.log({
  12. PROJECT_ID,
  13. BATCH_SIZE,
  14. VERBOSE_LOGGING: process.env.VERBOSE_LOGGING, // for batchedUpdate() logging
  15. })
  16. async function main() {
  17. if (PROJECT_ID) {
  18. await waitForDb()
  19. const { modifiedCount } = await db.projects.updateOne(
  20. { _id: ObjectId(PROJECT_ID), 'overleaf.history.allowDowngrade': true },
  21. { $unset: { 'overleaf.history.allowDowngrade': 1 } }
  22. )
  23. console.log(`modifiedCount: ${modifiedCount}`)
  24. } else {
  25. await batchedUpdate(
  26. 'projects',
  27. { 'overleaf.history.allowDowngrade': true },
  28. { $unset: { 'overleaf.history.allowDowngrade': 1 } }
  29. )
  30. }
  31. console.log('Final')
  32. }
  33. main()
  34. .then(() => {
  35. console.error('Done.')
  36. process.exit(0)
  37. })
  38. .catch(error => {
  39. console.error({ error })
  40. process.exit(1)
  41. })