20200608213302_saml-cache-indexes.mjs 742 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. const tags = ['saas']
  4. const indexes = [
  5. {
  6. key: {
  7. requestId: 1,
  8. },
  9. name: 'requestId_1',
  10. },
  11. {
  12. // expire after 24 hours
  13. expireAfterSeconds: 60 * 60 * 24,
  14. key: {
  15. createdAt: 1,
  16. },
  17. name: 'createdAt_1',
  18. },
  19. ]
  20. const migrate = async client => {
  21. const { db } = client
  22. await Helpers.addIndexesToCollection(db.samlCache, indexes)
  23. }
  24. const rollback = async client => {
  25. const { db } = client
  26. try {
  27. await Helpers.dropIndexesFromCollection(db.samlCache, indexes)
  28. } catch (err) {
  29. console.error('Something went wrong rolling back the migrations', err)
  30. }
  31. }
  32. export default {
  33. tags,
  34. migrate,
  35. rollback,
  36. }