20231025094810_sso_config_certificates_array.mjs 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.ssoConfigs,
  7. { certificate: { $exists: true }, certificates: { $exists: false } },
  8. [
  9. { $set: { certificates: ['$certificate'] } },
  10. {
  11. $unset: 'certificate',
  12. },
  13. ]
  14. )
  15. await batchedUpdate(
  16. db.ssoConfigs,
  17. { userFirstNameAttribute: null },
  18. { $unset: { userFirstNameAttribute: true } }
  19. )
  20. await batchedUpdate(
  21. db.ssoConfigs,
  22. { userLastNameAttribute: null },
  23. { $unset: { userLastNameAttribute: true } }
  24. )
  25. }
  26. const rollback = async client => {
  27. const { db } = client
  28. await batchedUpdate(
  29. db.ssoConfigs,
  30. { certificate: { $exists: false }, certificates: { $exists: true } },
  31. [
  32. { $set: { certificate: { $arrayElemAt: ['$certificates', 0] } } },
  33. {
  34. $unset: 'certificates',
  35. },
  36. ]
  37. )
  38. }
  39. export default {
  40. tags,
  41. migrate,
  42. rollback,
  43. }