20251222142959_emailNotifications_index_update.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. import { getCollectionInternal } from './lib/mongodb.mjs'
  4. const tags = ['server-pro', 'saas']
  5. const oldIndexes = [
  6. {
  7. key: {
  8. user_id: 1,
  9. recipient_id: 1,
  10. project_id: 1,
  11. },
  12. name: 'user_id_1_recipient_id_1_project_id_1',
  13. },
  14. {
  15. key: {
  16. recipient_id: 1,
  17. },
  18. name: 'recipientId_1',
  19. expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours
  20. },
  21. ]
  22. const newIndexes = [
  23. {
  24. key: {
  25. project_id: 1,
  26. },
  27. name: 'project_id_1',
  28. expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours
  29. },
  30. ]
  31. const migrate = async client => {
  32. const emailNotifications = await getCollectionInternal('emailNotifications')
  33. await Helpers.dropIndexesFromCollection(emailNotifications, oldIndexes)
  34. await Helpers.addIndexesToCollection(emailNotifications, newIndexes)
  35. }
  36. const rollback = async client => {
  37. const emailNotifications = await getCollectionInternal('emailNotifications')
  38. await Helpers.dropIndexesFromCollection(emailNotifications, newIndexes)
  39. await Helpers.addIndexesToCollection(emailNotifications, oldIndexes)
  40. }
  41. export default {
  42. tags,
  43. migrate,
  44. rollback,
  45. }