mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* upgrade gulp-babel * upgrade babel-eslint * upgrade eslint-friendly-formatter * start upgrading chai * start to upgrade eslint * restore skipped tests * start to upgrqde monk * fix linting and remove unused file * fix mocha notifications, and common tests * fix unit tests * start to fix initrgration tests * more integration tests fixes * upgrade monk to latest version * lint /scripts * migrations: start moving to /archive unused migrations and run eslint with --fix * lint migrations * fix more integration tests * fix test
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/*
|
|
* Migrate email to lowerCase version and add auth.local.lowerCaseUsername email
|
|
*/
|
|
|
|
let mongo = require('mongoskin');
|
|
let async = require('async');
|
|
|
|
let dbserver = 'url';
|
|
let dbname = 'dbname';
|
|
let countUsers = 0;
|
|
|
|
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
|
let dbUsers = db.collection('users');
|
|
|
|
console.log('Begins work on db');
|
|
|
|
function findUsers (gt) {
|
|
let query = {};
|
|
if (gt) query._id = {$gt: gt};
|
|
|
|
console.log(query);
|
|
|
|
dbUsers.find(query, {
|
|
fields: {_id: 1, auth: 1},
|
|
limit: 10000,
|
|
sort: {
|
|
_id: 1,
|
|
},
|
|
}).toArray(function (err, users) {
|
|
if (err) throw err;
|
|
|
|
let lastUser = null;
|
|
if (users.length === 10000) {
|
|
lastUser = users[users.length - 1];
|
|
}
|
|
|
|
async.eachLimit(users, 20, function (user, cb) {
|
|
countUsers++;
|
|
console.log('User: ', countUsers, user._id);
|
|
|
|
let update = {
|
|
$set: {},
|
|
};
|
|
|
|
if (user.auth && user.auth.local) {
|
|
if (user.auth.local.username) update.$set['auth.local.lowerCaseUsername'] = user.auth.local.username.toLowerCase();
|
|
if (user.auth.local.email) update.$set['auth.local.email'] = user.auth.local.email.toLowerCase();
|
|
}
|
|
|
|
dbUsers.update({
|
|
_id: user._id,
|
|
}, update, cb);
|
|
}, function (err) {
|
|
if (err) throw err;
|
|
|
|
if (lastUser && lastUser._id) {
|
|
findUsers(lastUser._id);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
findUsers();
|