20251110151140_create_notificationsPreferences_collection.mjs 868 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Helpers from './lib/helpers.mjs'
  2. import { getCollectionInternal } from './lib/mongodb.mjs'
  3. const tags = ['server-ce', 'server-pro', 'saas']
  4. const indexes = [
  5. {
  6. // compound index for querying both global (project_id: null) and project-specific notification preferences
  7. key: {
  8. user_id: 1,
  9. project_id: 1,
  10. },
  11. unique: true,
  12. name: 'user_id_1_project_id_1',
  13. },
  14. ]
  15. const migrate = async () => {
  16. const notificationsPreferences = await getCollectionInternal(
  17. 'notificationsPreferences'
  18. )
  19. await Helpers.addIndexesToCollection(notificationsPreferences, indexes)
  20. }
  21. const rollback = async () => {
  22. const notificationsPreferences = await getCollectionInternal(
  23. 'notificationsPreferences'
  24. )
  25. await Helpers.dropIndexesFromCollection(notificationsPreferences, indexes)
  26. }
  27. export default {
  28. tags,
  29. migrate,
  30. rollback,
  31. }