migration6.js 1016 B

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