20190912145022_create_projectImportFailures_indexes.js 857 B

12345678910111213141516171819202122232425262728293031323334
  1. /* eslint-disable no-unused-vars */
  2. const Helpers = require('./lib/helpers')
  3. const { getCollectionInternal } = require('../app/src/infrastructure/mongodb')
  4. exports.tags = ['saas']
  5. const indexes = [
  6. {
  7. key: {
  8. v1_project_id: 1,
  9. },
  10. name: 'v1_project_id_1',
  11. },
  12. ]
  13. async function getCollection() {
  14. // NOTE: This is a stale collection, it will get dropped in a later migration.
  15. return await getCollectionInternal('projectImportFailures')
  16. }
  17. exports.migrate = async client => {
  18. const collection = await getCollection()
  19. await Helpers.addIndexesToCollection(collection, indexes)
  20. }
  21. exports.rollback = async client => {
  22. const collection = await getCollection()
  23. try {
  24. await Helpers.dropIndexesFromCollection(collection, indexes)
  25. } catch (err) {
  26. console.error('Something went wrong rolling back the migrations', err)
  27. }
  28. }