migration7.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import async from "async";
  2. /**
  3. * Migration 7
  4. *
  5. * Migration for adding anonymous song requests 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 7. Finding users with document version 2.`);
  16. userModel.updateMany(
  17. { documentVersion: 2 },
  18. { $set: { documentVersion: 3, "preferences.anonymousSongRequests": false } },
  19. (err, res) => {
  20. if (err) next(err);
  21. else {
  22. this.log(
  23. "INFO",
  24. `Migration 7. 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. }