20210407085118_token-expiry-with-ttl-index.js 704 B

123456789101112131415161718192021222324252627282930313233343536
  1. const Helpers = require('./lib/helpers')
  2. exports.tags = ['server-ce', 'server-pro', 'saas']
  3. const indexes = {
  4. tokens: [
  5. {
  6. // expire all tokens 90 days after they are created
  7. expireAfterSeconds: 90 * 24 * 60 * 60,
  8. key: {
  9. createdAt: 1,
  10. },
  11. name: 'createdAt_1',
  12. },
  13. ],
  14. }
  15. exports.migrate = async client => {
  16. const { db } = client
  17. await Promise.all(
  18. Object.keys(indexes).map(key =>
  19. Helpers.addIndexesToCollection(db[key], indexes[key])
  20. )
  21. )
  22. }
  23. exports.rollback = async client => {
  24. const { db } = client
  25. await Promise.all(
  26. Object.keys(indexes).map(key =>
  27. Helpers.dropIndexesFromCollection(db[key], indexes[key])
  28. )
  29. )
  30. }