|
@@ -2,11 +2,14 @@
|
|
|
/* eslint-disable no-undef, no-var, vars-on-top, no-restricted-globals, regex/invalid, import/extensions */
|
|
/* eslint-disable no-undef, no-var, vars-on-top, no-restricted-globals, regex/invalid, import/extensions */
|
|
|
// ignore lint error because this file is js as mongoshell
|
|
// ignore lint error because this file is js as mongoshell
|
|
|
|
|
|
|
|
-var processor = require('./processor.js');
|
|
|
|
|
-
|
|
|
|
|
var pagesCollection = db.getCollection('pages');
|
|
var pagesCollection = db.getCollection('pages');
|
|
|
var revisionsCollection = db.getCollection('revisions');
|
|
var revisionsCollection = db.getCollection('revisions');
|
|
|
|
|
|
|
|
|
|
+var getProcessorArray = require('./processor.js');
|
|
|
|
|
+
|
|
|
|
|
+var migrationType = process.env.MIGRATION_TYPE;
|
|
|
|
|
+var processors = getProcessorArray(migrationType);
|
|
|
|
|
+
|
|
|
var operations = [];
|
|
var operations = [];
|
|
|
|
|
|
|
|
var batchSize = process.env.BATCH_SIZE ?? 100; // default 100 revisions in 1 bulkwrite
|
|
var batchSize = process.env.BATCH_SIZE ?? 100; // default 100 revisions in 1 bulkwrite
|
|
@@ -23,10 +26,14 @@ function replaceLatestRevisions(body, processors) {
|
|
|
return replacedBody;
|
|
return replacedBody;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+if (processors.length === 0) {
|
|
|
|
|
+ throw Error('No valid processors found. Please enter a valid environment variable');
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
pagesCollection.find({}).forEach((doc) => {
|
|
pagesCollection.find({}).forEach((doc) => {
|
|
|
if (doc.revision) {
|
|
if (doc.revision) {
|
|
|
var revision = revisionsCollection.findOne({ _id: doc.revision });
|
|
var revision = revisionsCollection.findOne({ _id: doc.revision });
|
|
|
- var replacedBody = replaceLatestRevisions(revision.body, [...processor]);
|
|
|
|
|
|
|
+ var replacedBody = replaceLatestRevisions(revision.body, [...processors]);
|
|
|
var operation = {
|
|
var operation = {
|
|
|
updateOne: {
|
|
updateOne: {
|
|
|
filter: { _id: revision._id },
|
|
filter: { _id: revision._id },
|