migration2WIP.js 999 B

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