20190912145014_create_notifications_indexes.mjs 790 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. const tags = ['server-ce', 'server-pro', 'saas']
  4. const indexes = [
  5. {
  6. key: {
  7. expires: 1,
  8. },
  9. name: 'expires_1',
  10. expireAfterSeconds: 10,
  11. },
  12. {
  13. key: {
  14. key: 1,
  15. },
  16. name: 'key_1',
  17. },
  18. {
  19. key: {
  20. user_id: 1,
  21. },
  22. name: 'user_id_1',
  23. },
  24. ]
  25. const migrate = async client => {
  26. const { db } = client
  27. await Helpers.addIndexesToCollection(db.notifications, indexes)
  28. }
  29. const rollback = async client => {
  30. const { db } = client
  31. try {
  32. await Helpers.dropIndexesFromCollection(db.notifications, indexes)
  33. } catch (err) {
  34. console.error('Something went wrong rolling back the migrations', err)
  35. }
  36. }
  37. export default {
  38. tags,
  39. migrate,
  40. rollback,
  41. }