20250115110745_oauth_user_id_index_no_partial.mjs 888 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. const tags = ['server-ce', 'server-pro', 'saas']
  4. const oldIndex = {
  5. key: { user_id: 1 },
  6. name: 'pat_user_id_1',
  7. partialFilterExpression: { type: 'pat' },
  8. }
  9. const newIndex = {
  10. key: { user_id: 1 },
  11. name: 'user_id_1',
  12. }
  13. const migrate = async client => {
  14. const { db } = client
  15. await Helpers.addIndexesToCollection(db.oauthAccessTokens, [newIndex])
  16. await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [oldIndex])
  17. }
  18. const rollback = async client => {
  19. const { db } = client
  20. try {
  21. await Helpers.addIndexesToCollection(db.oauthAccessTokens, [oldIndex])
  22. await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [newIndex])
  23. } catch (err) {
  24. console.error('Something went wrong rolling back the migrations', err)
  25. }
  26. }
  27. export default {
  28. tags,
  29. migrate,
  30. rollback,
  31. }