20230428154643_history_chunks_garbage_collection_index.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* eslint-disable no-unused-vars */
  2. import Helpers from './lib/helpers.mjs'
  3. const tags = ['server-ce', 'server-pro', 'saas']
  4. const oldIndexes = [
  5. {
  6. key: {
  7. state: 1,
  8. },
  9. name: 'state_1',
  10. partialFilterExpression: {
  11. state: 'deleted',
  12. },
  13. },
  14. {
  15. key: {
  16. state: -1,
  17. },
  18. name: 'state_pending',
  19. partialFilterExpression: {
  20. state: 'pending',
  21. },
  22. },
  23. ]
  24. const newIndexes = [
  25. {
  26. key: {
  27. updatedAt: 1,
  28. },
  29. name: 'deleted_updated_at',
  30. partialFilterExpression: {
  31. state: 'deleted',
  32. },
  33. },
  34. {
  35. key: {
  36. updatedAt: -1,
  37. },
  38. name: 'pending_updated_at',
  39. partialFilterExpression: {
  40. state: 'pending',
  41. },
  42. },
  43. ]
  44. const migrate = async client => {
  45. const { db } = client
  46. await Helpers.addIndexesToCollection(db.projectHistoryChunks, newIndexes)
  47. await Helpers.dropIndexesFromCollection(db.projectHistoryChunks, oldIndexes)
  48. }
  49. const rollback = async client => {
  50. const { db } = client
  51. await Helpers.addIndexesToCollection(db.projectHistoryChunks, oldIndexes)
  52. await Helpers.dropIndexesFromCollection(db.projectHistoryChunks, newIndexes)
  53. }
  54. export default {
  55. tags,
  56. migrate,
  57. rollback,
  58. }