20251016112728_create_emailNotifications_collection.mjs 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 indexes = [
  6. {
  7. key: {
  8. scheduledAt: 1,
  9. },
  10. name: 'scheduledAt_1',
  11. expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours
  12. },
  13. {
  14. // used for querying notifications to find possible duplicates
  15. unique: false,
  16. key: {
  17. user_id: 1,
  18. recipient_id: 1,
  19. project_id: 1,
  20. },
  21. name: 'user_id_1_recipient_id_1_project_id_1',
  22. },
  23. ]
  24. const migrate = async () => {
  25. const emailNotifications = await getCollectionInternal('emailNotifications')
  26. await Helpers.addIndexesToCollection(emailNotifications, indexes)
  27. }
  28. const rollback = async () => {
  29. const emailNotifications = await getCollectionInternal('emailNotifications')
  30. await Helpers.dropIndexesFromCollection(emailNotifications, indexes)
  31. }
  32. export default {
  33. tags,
  34. migrate,
  35. rollback,
  36. }