mirror of
https://github.com/wassname/talk.git
synced 2026-08-06 13:41:02 +08:00
fixed migration issues
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user