20190912145033_create_userstubs_indexes.mjs 892 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. import mongodb from './lib/mongodb.mjs'
  4. const { getCollectionInternal } = mongodb
  5. const tags = ['saas']
  6. const indexes = [
  7. {
  8. key: {
  9. 'overleaf.id': 1,
  10. },
  11. name: 'overleaf.id_1',
  12. },
  13. ]
  14. async function getCollection() {
  15. // NOTE: This is a stale collection, it will get dropped in a later migration.
  16. return await getCollectionInternal('userstubs')
  17. }
  18. const migrate = async client => {
  19. const collection = await getCollection()
  20. await Helpers.addIndexesToCollection(collection, indexes)
  21. }
  22. const rollback = async client => {
  23. const collection = await getCollection()
  24. try {
  25. await Helpers.dropIndexesFromCollection(collection, indexes)
  26. } catch (err) {
  27. console.error('Something went wrong rolling back the migrations', err)
  28. }
  29. }
  30. export default {
  31. tags,
  32. migrate,
  33. rollback,
  34. }