20230207134844_group_invite_emails_to_lowercase.mjs 810 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  2. const tags = ['saas']
  3. const migrate = async client => {
  4. const { db } = client
  5. await batchedUpdate(
  6. db.subscriptions,
  7. {
  8. 'teamInvites.0': {
  9. $exists: true,
  10. },
  11. },
  12. [
  13. {
  14. $set: {
  15. teamInvites: {
  16. $map: {
  17. input: '$teamInvites',
  18. in: {
  19. $mergeObjects: [
  20. '$$this',
  21. {
  22. email: {
  23. $toLower: '$$this.email',
  24. },
  25. },
  26. ],
  27. },
  28. },
  29. },
  30. },
  31. },
  32. ]
  33. )
  34. }
  35. const rollback = async () => {
  36. // There is no way back.
  37. }
  38. export default {
  39. tags,
  40. migrate,
  41. rollback,
  42. }