20230406125632_oauth_tokens_ttl.mjs 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['server-ce', 'server-pro', 'saas']
  3. const ACCESS_TOKENS_INDEX = {
  4. name: 'expiresAt_1',
  5. key: { expiresAt: 1 },
  6. partialFilterExpression: { expiresAt: { $exists: true } },
  7. expireAfterSeconds: 0,
  8. }
  9. const AUTHORIZATION_CODES_INDEX = {
  10. name: 'expiresAt_1',
  11. key: { expiresAt: 1 },
  12. partialFilterExpression: { expiresAt: { $exists: true } },
  13. expireAfterSeconds: 0,
  14. }
  15. const migrate = async ({ db }) => {
  16. await Helpers.addIndexesToCollection(db.oauthAccessTokens, [
  17. ACCESS_TOKENS_INDEX,
  18. ])
  19. await Helpers.addIndexesToCollection(db.oauthAuthorizationCodes, [
  20. AUTHORIZATION_CODES_INDEX,
  21. ])
  22. }
  23. const rollback = async ({ db }) => {
  24. await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [
  25. ACCESS_TOKENS_INDEX,
  26. ])
  27. await Helpers.dropIndexesFromCollection(db.oauthAuthorizationCodes, [
  28. AUTHORIZATION_CODES_INDEX,
  29. ])
  30. }
  31. export default {
  32. tags,
  33. migrate,
  34. rollback,
  35. }