migration19.js 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import async from "async";
  2. /**
  3. * Migration 19
  4. *
  5. * Migration for news showToNewUsers property.
  6. *
  7. * @param {object} MigrationModule - the MigrationModule
  8. * @returns {Promise} - returns promise
  9. */
  10. export default async function migrate(MigrationModule) {
  11. const newsModel = await MigrationModule.runJob("GET_MODEL", { modelName: "news" }, this);
  12. return new Promise((resolve, reject) => {
  13. async.waterfall(
  14. [
  15. next => {
  16. this.log("INFO", `Migration 19. Finding news with version 2.`);
  17. newsModel.updateMany(
  18. { documentVersion: 2 },
  19. {
  20. $set: { documentVersion: 3, showToNewUsers: false }
  21. },
  22. (err, res) => {
  23. if (err) next(err);
  24. else {
  25. this.log(
  26. "INFO",
  27. `Migration 19. Matched: ${res.matchedCount}, modified: ${res.modifiedCount}, ok: ${res.ok}.`
  28. );
  29. next();
  30. }
  31. }
  32. );
  33. }
  34. ],
  35. err => {
  36. if (err) {
  37. reject(new Error(err));
  38. } else {
  39. resolve();
  40. }
  41. }
  42. );
  43. });
  44. }