back_fill_hiding_ai_features.mjs 951 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { db } from '../../app/src/infrastructure/mongodb.mjs'
  2. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  3. import { scriptRunner } from '../lib/ScriptRunner.mjs'
  4. async function main(trackProgress) {
  5. // Set aiFeatures.enabled to false where writefull.enabled is false
  6. await batchedUpdate(
  7. db.users,
  8. { 'writefull.enabled': false },
  9. { $set: { 'aiFeatures.enabled': false } },
  10. undefined,
  11. undefined,
  12. { trackProgress }
  13. )
  14. // Set aiFeatures.enabled to true for all other cases (true, null, or not exists)
  15. await batchedUpdate(
  16. db.users,
  17. { 'writefull.enabled': { $ne: false } },
  18. { $set: { 'aiFeatures.enabled': true } },
  19. undefined,
  20. undefined,
  21. { trackProgress }
  22. )
  23. console.log('completed syncing writefull state with error assist')
  24. }
  25. export default main
  26. try {
  27. await scriptRunner(main)
  28. process.exit(0)
  29. } catch (error) {
  30. console.error({ error })
  31. process.exit(1)
  32. }