migration6.js 1013 B

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