v3 migration: first finished version that contains all models

This commit is contained in:
Matteo Pagliazzi
2016-05-01 16:27:04 +02:00
parent 4457b1c18c
commit e8024f98e1
8 changed files with 610 additions and 59 deletions

View File

@@ -1,9 +1,4 @@
/*
members must be removed
*/
// Migrate users collection to new schema
// This should run AFTER challenges migration
// Migrate challenges collection to new schema (except for members)
// The console-stamp module must be installed (not included in package.json)
@@ -104,6 +99,8 @@ function processChallenges (afterId) {
delete oldChallenge.rewards;
delete oldChallenge.todos;
var createdAt = oldChallenge.timestamp;
oldChallenge.memberCount = oldChallenge.members.length;
if (!oldChallenge.prize <= 0) oldChallenge.prize = 0;
if (!oldChallenge.name) oldChallenge.name = 'challenge name';
@@ -114,6 +111,8 @@ function processChallenges (afterId) {
var newChallenge = new NewChallenge(oldChallenge);
newChallenge.createdAt = createdAt;
oldTasks.forEach(function (oldTask) {
oldTask._id = oldTask.id; // keep the old uuid unless duplicated
delete oldTask.id;
@@ -139,9 +138,12 @@ function processChallenges (afterId) {
batchInsertChallenges.insert(newChallenge.toObject());
});
console.log(`Saving ${oldChallenges.length} users and ${processedTasks} tasks.`);
console.log(`Saving ${oldChallenges.length} challenges and ${processedTasks} tasks.`);
return batchInsertChallenges.execute();
return Q.all([
batchInsertChallenges.execute(),
batchInsertTasks.execute(),
]);
})
.then(function () {
totoalProcessedTasks += processedTasks;
@@ -178,5 +180,5 @@ Q.all([
return processChallenges();
})
.catch(function (err) {
console.error(err);
console.error(err.stack || err);
});