Browse Source

fix: Prevent migration 18 running once migration 20 has been run

Owen Diffey 2 years ago
parent
commit
ef425d3bec

+ 1 - 1
backend/logic/db/index.js

@@ -12,7 +12,7 @@ const REQUIRED_DOCUMENT_VERSIONS = {
 	punishment: 1,
 	queueSong: 1,
 	report: 5,
-	song: 7,
+	song: 8,
 	station: 8,
 	user: 3
 };

+ 1 - 1
backend/logic/db/schemas/song.js

@@ -16,5 +16,5 @@ export default {
 	verifiedBy: { type: String },
 	verifiedAt: { type: Date },
 	discogs: { type: Object },
-	documentVersion: { type: Number, default: 7, required: true }
+	documentVersion: { type: Number, default: 8, required: true }
 };

+ 16 - 1
backend/logic/migration/migrations/migration20.js

@@ -4,13 +4,14 @@ import mongoose from "mongoose";
 /**
  * Migration 20
  *
- * Migration for station overhaul (WIP)
+ * Migration for station overhaul and preventing migration18 from always running
  *
  * @param {object} MigrationModule - the MigrationModule
  * @returns {Promise} - returns promise
  */
 export default async function migrate(MigrationModule) {
 	const stationModel = await MigrationModule.runJob("GET_MODEL", { modelName: "station" }, this);
+	const songModel = await MigrationModule.runJob("GET_MODEL", { modelName: "song" }, this);
 
 	return new Promise((resolve, reject) => {
 		async.waterfall(
@@ -76,6 +77,20 @@ export default async function migrate(MigrationModule) {
 							}
 						}
 					);
+				},
+
+				next => {
+					songModel.updateMany({ documentVersion: 7 }, { $set: { documentVersion: 8 } }, (err, res) => {
+						if (err) next(err);
+						else {
+							this.log(
+								"INFO",
+								`Migration 20 (songs). Matched: ${res.matchedCount}, modified: ${res.modifiedCount}, ok: ${res.ok}.`
+							);
+
+							next();
+						}
+					});
 				}
 			],
 			err => {