migration17.js 976 B

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