mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-22 03:34:14 +00:00
merge @paglias migrations into our one big migration, so I can run it
all at once when the time comes. Had to make some changes (will comment no github)
This commit is contained in:
parent
ea54f0aa75
commit
0151484279
3 changed files with 20 additions and 46 deletions
|
|
@ -1,17 +0,0 @@
|
|||
db.users.find().forEach(function(user){
|
||||
var tags = user.tags;
|
||||
|
||||
_.each(user.tasks, function(task){
|
||||
_.each(task.tags, function(val, key){
|
||||
_.each(tags, function(tag){
|
||||
if(key == tag.id) delete task.tags[key];
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
db.users.update({_id:user._id}, user);
|
||||
} catch(e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
|
@ -1,5 +1,20 @@
|
|||
var groups = {};
|
||||
|
||||
db.users.find().forEach(function(user){
|
||||
|
||||
// add_invites_to_groups
|
||||
if(user.invitations){
|
||||
if(user.invitations.party){
|
||||
db.groups.update({_id: user.invitations.party.id}, {$addToSet:{invites:user._id}});
|
||||
}
|
||||
|
||||
if(user.invitations.guilds){
|
||||
_.each(user.invitations.guilds, function(guild){
|
||||
db.groups.update({_id: guild.id}, {$addToSet:{invites:user._id}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup broken tags
|
||||
_.each(user.tasks, function(task){
|
||||
_.each(task.tags, function(val, key){
|
||||
|
|
@ -11,8 +26,8 @@ db.users.find().forEach(function(user){
|
|||
|
||||
// Migrate to TaskSchema subdocs!!
|
||||
if (!user.tasks) {
|
||||
printjson(user.auth);
|
||||
// FIXME before deploying!
|
||||
print(user._id);
|
||||
} else {
|
||||
_.each(['habit', 'daily', 'todo', 'reward'], function(type) {
|
||||
// we use _.transform instead of a simple _.where in order to maintain sort-order
|
||||
|
|
@ -37,9 +52,10 @@ db.users.find().forEach(function(user){
|
|||
});
|
||||
|
||||
// Remove old groups.*.challenges, they're not compatible with the new system
|
||||
db.groups.update({},{$pull:{challenges:1}},{multi:true});
|
||||
// set member counts
|
||||
db.groups.find().forEach(function(group){
|
||||
db.groups.update({_id:group._id}, {
|
||||
$set:{memberCount: _.size(group.members)}
|
||||
$set:{memberCount: _.size(group.members)},
|
||||
$pull:{challenges:1}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
var groups = {};
|
||||
|
||||
db.users.find().forEach(function(user){
|
||||
if(user.invitations){
|
||||
if(user.invitations.party){
|
||||
groups[user.invitations.party.id] = groups[user.invitations.party.id] || [];
|
||||
groups[user.invitations.party.id].push(user._id);
|
||||
}
|
||||
|
||||
if(user.invitations.guilds){
|
||||
_.each(user.invitations.guilds, function(guild){
|
||||
groups[guild.id] = groups[guild.id] || [];
|
||||
groups[guild.id].push(user._id);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_.each(groups, function(usersInvited, groupId){
|
||||
try {
|
||||
db.groups.update({_id: groupId}, {$set: {'group.invites': usersInvited} });
|
||||
} catch(e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue