20260213102825_swap_writefull_enabled_for_initialized.mjs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  4. const tags = ['saas']
  5. const migrate = async client => {
  6. const { db } = client
  7. // if writefull.enabled is unset or null then the account has no promotion attached yet
  8. await batchedUpdate(db.users, {}, [
  9. {
  10. $set: {
  11. 'writefull.initialized': {
  12. $or: [
  13. { $eq: ['$writefull.enabled', true] },
  14. { $eq: ['$writefull.enabled', false] },
  15. ],
  16. },
  17. },
  18. },
  19. ])
  20. console.log('completed migration to writefull.initialized')
  21. }
  22. const rollback = async client => {
  23. const { db } = client
  24. // unset the user.writefull.initialized value only if its been set
  25. await batchedUpdate(
  26. db.users,
  27. { 'writefull.initialized': { $exists: true } },
  28. { $unset: { 'writefull.initialized': 1 } }
  29. )
  30. console.log('completed rollback of writefull.initialized migration')
  31. }
  32. export default {
  33. tags,
  34. migrate,
  35. rollback,
  36. }