20210924140139_splittests-name-index.mjs 747 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Helpers from './lib/helpers.mjs'
  2. import mongodb from './lib/mongodb.mjs'
  3. const { getCollectionInternal } = mongodb
  4. const tags = ['saas']
  5. const indexes = [
  6. {
  7. key: {
  8. name: 1,
  9. },
  10. unique: true,
  11. name: 'name_1',
  12. },
  13. ]
  14. async function getCollection() {
  15. // NOTE: We do not access the splittests collection directly. Fetch it here.
  16. return await getCollectionInternal('splittests')
  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. await Helpers.dropIndexesFromCollection(collection, indexes)
  25. }
  26. export default {
  27. tags,
  28. migrate,
  29. rollback,
  30. }