20260430120000_update_libraryReferences_userId_updatedAt_index.mjs 729 B

12345678910111213141516171819202122232425262728293031
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['saas']
  3. const oldIndex = {
  4. key: { userId: 1, updatedAt: 1 },
  5. name: 'userId_1_updatedAt_1',
  6. }
  7. const newIndex = {
  8. key: { userId: 1, updatedAt: 1, _id: 1 },
  9. name: 'userId_1_updatedAt_1__id_1',
  10. }
  11. const migrate = async client => {
  12. const { db } = client
  13. await Helpers.addIndexesToCollection(db.libraryReferences, [newIndex])
  14. await Helpers.dropIndexesFromCollection(db.libraryReferences, [oldIndex])
  15. }
  16. const rollback = async client => {
  17. const { db } = client
  18. await Helpers.addIndexesToCollection(db.libraryReferences, [oldIndex])
  19. await Helpers.dropIndexesFromCollection(db.libraryReferences, [newIndex])
  20. }
  21. export default {
  22. tags,
  23. migrate,
  24. rollback,
  25. }