20260216141836_back_fill_hiding_ai_features.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* eslint-disable no-unused-vars */
  2. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  3. const tags = ['saas']
  4. const migrate = async client => {
  5. const { db } = client
  6. // Set aiFeatures.enabled to false where writefull.enabled is false
  7. await batchedUpdate(
  8. db.users,
  9. {
  10. 'writefull.enabled': false,
  11. // dont re-set in cases where we already set aiFeatures, ie: by running the script
  12. 'aiFeatures.enabled': { $exists: false },
  13. },
  14. { $set: { 'aiFeatures.enabled': false } }
  15. )
  16. // Set aiFeatures.enabled to true for all other cases (true, null, or not exists)
  17. await batchedUpdate(
  18. db.users,
  19. {
  20. 'writefull.enabled': { $ne: false },
  21. // dont re-set in cases where we already set aiFeatures, ie: by running the script
  22. 'aiFeatures.enabled': { $exists: false },
  23. },
  24. { $set: { 'aiFeatures.enabled': true } }
  25. )
  26. console.log(
  27. 'completed syncing rename of aiErrorAssist.enabled to aiFeatures.enabled'
  28. )
  29. }
  30. const rollback = async client => {
  31. const { db } = client
  32. // unset the user.writefull.initialized value only if its been set
  33. await batchedUpdate(
  34. db.users,
  35. { 'aiFeatures.enabled': { $exists: true } },
  36. { $unset: { 'aiFeatures.enabled': 1 } }
  37. )
  38. console.log('completed rollback of aiFeatures.enabled migration')
  39. }
  40. export default {
  41. tags,
  42. migrate,
  43. rollback,
  44. }