20190912145022_create_projectImportFailures_indexes.mjs 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. v1_project_id: 1,
  10. },
  11. name: 'v1_project_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('projectImportFailures')
  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. }