20260504100000_cleanup_users_split_tests.mjs 755 B

123456789101112131415161718192021222324252627282930
  1. import { db } from './lib/mongodb.mjs'
  2. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  3. const tags = ['saas', 'server-ce', 'server-pro']
  4. const migrate = async () => {
  5. const splitTests = await db.splittests.find().toArray()
  6. const toCleanup = {}
  7. for (const splitTest of splitTests) {
  8. if (splitTest.archived) {
  9. toCleanup[`splitTests.${splitTest.name}`] = 1
  10. }
  11. }
  12. // Take the easy route and unset all the archived split tests on all the users with any split test assignment.
  13. await batchedUpdate(
  14. db.users,
  15. { splitTests: { $exists: true } },
  16. { $unset: toCleanup }
  17. )
  18. }
  19. const rollback = async () => {
  20. // The data is gone. Nothing to revert to.
  21. }
  22. export default {
  23. tags,
  24. migrate,
  25. rollback,
  26. }