migration17.js 973 B

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