migration19.js 1004 B

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