20250318144744_add_subscription_and_deleted_subscription_indexes.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['saas']
  3. const deletedSubscriptionIndexes = [
  4. {
  5. key: {
  6. 'subscription.groupPlan': 1,
  7. },
  8. name: 'subscription.groupPlan_1',
  9. },
  10. ]
  11. const subscriptionIndexes = [
  12. {
  13. key: {
  14. groupPlan: 1,
  15. },
  16. name: 'groupPlan_1',
  17. },
  18. ]
  19. const migrate = async client => {
  20. const { db } = client
  21. await Helpers.addIndexesToCollection(
  22. db.deletedSubscriptions,
  23. deletedSubscriptionIndexes
  24. )
  25. await Helpers.addIndexesToCollection(db.subscriptions, subscriptionIndexes)
  26. }
  27. const rollback = async client => {
  28. const { db } = client
  29. try {
  30. await Helpers.dropIndexesFromCollection(
  31. db.deletedSubscriptions,
  32. deletedSubscriptionIndexes
  33. )
  34. } catch (err) {
  35. console.error(
  36. 'Something went wrong rolling back the deletedSubscriptions migration',
  37. err
  38. )
  39. }
  40. try {
  41. await Helpers.dropIndexesFromCollection(
  42. db.subscriptions,
  43. subscriptionIndexes
  44. )
  45. } catch (err) {
  46. console.error(
  47. 'Something went wrong rolling back the subscription migration',
  48. err
  49. )
  50. }
  51. }
  52. export default {
  53. tags,
  54. migrate,
  55. rollback,
  56. }