fixed migration issues

This commit is contained in:
Wyatt Johnson
2017-11-17 09:17:43 -07:00
parent 90a9ff251d
commit 73cec00fb9
3 changed files with 46 additions and 20 deletions
+16 -6
View File
@@ -22,8 +22,7 @@ module.exports = {
return;
}
// Create a new batch operation.
let batch = CommentModel.collection.initializeUnorderedBulkOp();
const updates = [];
// Loop over the comments retrieved, updating the tag structure.
for (let {id, tags} of comments) {
@@ -73,11 +72,22 @@ module.exports = {
created_at
}));
// Execute the batch operation.
batch.find({id}).updateOne({$set: {tags}});
updates.push({query: {id}, update: {$set: {tags}}});
}
// Execute the batch update operation.
await batch.execute();
if (updates.length > 0) {
// Create a new batch operation.
let batch = CommentModel.collection.initializeUnorderedBulkOp();
for (const {query, update} of updates) {
// Execute the batch operation.
batch.find(query).updateOne(update);
}
// Execute the batch update operation.
await batch.execute();
}
}
};
+16 -8
View File
@@ -14,9 +14,7 @@ const mapping = {
module.exports = {
async up() {
// Setup the batch operation.
const batch = ActionModel.collection.initializeUnorderedBulkOp();
const updates = [];
for (const item_type in mapping) {
const mappings = mapping[item_type];
@@ -32,19 +30,29 @@ module.exports = {
// group_id: <NEW_GROUP_ID>
// }
batch.find({
updates.push({query: {
group_id: OLD_GROUP_ID,
item_type,
}).update({
}, update: {
$set: {
group_id: NEW_GROUP_ID,
},
});
}});
}
}
// Execute the batch update operation.
await batch.execute();
if (updates.length > 0) {
// Setup the batch operation.
const batch = ActionModel.collection.initializeUnorderedBulkOp();
for (const {query, update} of updates) {
batch.find(query).update(update);
}
// Execute the batch update operation.
await batch.execute();
}
}
};
+14 -6
View File
@@ -22,12 +22,10 @@ module.exports = {
const created_at = Date.now();
// Create a new batch operation.
let bulk = UserModel.collection.initializeUnorderedBulkOp();
// Get the first batch of users.
let cursor = await getUserBatch();
const updates = [];
while (await cursor.hasNext()) {
const user = await cursor.next();
@@ -201,11 +199,21 @@ module.exports = {
throw new Error(`${status} is an invalid status`);
}
bulk.find({id}).updateOne(update);
updates.push({query: {id}, update});
}
// Execute the bulk update operation.
await bulk.execute();
if (updates.length > 0) {
// Create a new batch operation.
let bulk = UserModel.collection.initializeUnorderedBulkOp();
for (const {query, update} of updates) {
bulk.find(query).updateOne(update);
}
// Execute the bulk update operation.
await bulk.execute();
}
}
};