mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
v3 migration: first finished version that contains all models
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user