mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-20 12:48:52 +00:00
re: d3eed22 , migration to fix 0'd dayStarts (@paglias, thanks for the fix!)
This commit is contained in:
parent
68bb5993c9
commit
caaebe01a2
2 changed files with 34 additions and 1 deletions
32
migrations/20131127_restore_dayStart.js
Normal file
32
migrations/20131127_restore_dayStart.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// node .migrations/20131127_restore_dayStart.js
|
||||
|
||||
var mongo = require('mongoskin');
|
||||
var _ = require('lodash');
|
||||
|
||||
var backupUsers = mongo.db('localhost:27017/habitrpg_old?auto_reconnect').collection('users');
|
||||
var liveUsers = mongo.db('localhost:27017/habitrpg_new?auto_reconnect').collection('users');
|
||||
|
||||
var query = {'preferences.dayStart':{$exists:1,$ne:0}};
|
||||
var select = {'preferences.dayStart': 1};
|
||||
|
||||
backupUsers.count(query, function(err, count){
|
||||
if (err) return console.error(err);
|
||||
backupUsers.findEach(query, select, {batchSize:20}, function(err, before){
|
||||
if (err) return console.error(err);
|
||||
if (!before) { count--; return console.log('!before'); }
|
||||
liveUsers.findById(before._id, function(err, after){
|
||||
if (err) return console.error(err);
|
||||
if (!after) { count--; return console.log(before._id + ' deleted?'); }
|
||||
|
||||
var dayStart = +before.preferences.dayStart;
|
||||
if (after.preferences.dayStart == 0 && dayStart != 0){
|
||||
dayStart = (_.isNaN(dayStart) || dayStart < 0 || dayStart > 24) ? 0 : dayStart;
|
||||
} else {
|
||||
dayStart = after.preferences.dayStart;
|
||||
}
|
||||
|
||||
liveUsers.update({_id:after._id}, {$inc:{_v:1}, $set:{'preferences.dayStart':dayStart}});
|
||||
if (--count <= 0) console.log("DONE!");
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
@ -77,6 +77,7 @@
|
|||
"karma-chai-plugins": "~0.1.0",
|
||||
"mocha": "~1.12.1",
|
||||
"karma-mocha": "~0.1.0",
|
||||
"csv": "~0.3.6"
|
||||
"csv": "~0.3.6",
|
||||
"mongoskin": "~0.6.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue