mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Upgrade tests tools and lint migrations and scripts (part 2) (#9998)
* 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
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
db.users.update(
|
||||
{'purchased.plan.customerId': {$ne: null}, 'purchased.plan.dateUpdated': null},
|
||||
{
|
||||
$set: {'purchased.plan.dateUpdated': new Date('12/01/2014')},
|
||||
$unset: {'purchased.plan.datedUpdated': ''},
|
||||
},
|
||||
{multi: true}
|
||||
);
|
||||
95
migrations/archive/2015/20150124_mountmaster_fix.js
Normal file
95
migrations/archive/2015/20150124_mountmaster_fix.js
Normal file
@@ -0,0 +1,95 @@
|
||||
let migrationName = '20150124_mountmaster_fix.js';
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/**
|
||||
* https://github.com/HabitRPG/habitrpg/pull/4374#issuecomment-71038795
|
||||
* Convert false to null for mounts that used to be owned.
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // CHANGE THIS FOR PRODUCTION DATABASE
|
||||
|
||||
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
||||
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
||||
// adapted to work with it. Before this migration is used again any lodash method should
|
||||
// be checked for compatibility against the v4 changelog and changed if necessary.
|
||||
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/habitrpg?auto_reconnect`).collection('users');
|
||||
|
||||
let query = {
|
||||
'items.mounts': {$exists: true},
|
||||
};
|
||||
|
||||
let fields = {
|
||||
'items.mounts': 1,
|
||||
};
|
||||
|
||||
let animals = ['Wolf-Base', 'Wolf-White', 'Wolf-Desert', 'Wolf-Red', 'Wolf-Shade', 'Wolf-Skeleton', 'Wolf-Zombie', 'Wolf-CottonCandyPink', 'Wolf-CottonCandyBlue', 'Wolf-Golden', 'TigerCub-Base', 'TigerCub-White', 'TigerCub-Desert', 'TigerCub-Red', 'TigerCub-Shade', 'TigerCub-Skeleton', 'TigerCub-Zombie', 'TigerCub-CottonCandyPink', 'TigerCub-CottonCandyBlue', 'TigerCub-Golden', 'PandaCub-Base', 'PandaCub-White', 'PandaCub-Desert', 'PandaCub-Red', 'PandaCub-Shade', 'PandaCub-Skeleton', 'PandaCub-Zombie', 'PandaCub-CottonCandyPink', 'PandaCub-CottonCandyBlue', 'PandaCub-Golden', 'LionCub-Base', 'LionCub-White', 'LionCub-Desert', 'LionCub-Red', 'LionCub-Shade', 'LionCub-Skeleton', 'LionCub-Zombie', 'LionCub-CottonCandyPink', 'LionCub-CottonCandyBlue', 'LionCub-Golden', 'Fox-Base', 'Fox-White', 'Fox-Desert', 'Fox-Red', 'Fox-Shade', 'Fox-Skeleton', 'Fox-Zombie', 'Fox-CottonCandyPink', 'Fox-CottonCandyBlue', 'Fox-Golden', 'FlyingPig-Base', 'FlyingPig-White', 'FlyingPig-Desert', 'FlyingPig-Red', 'FlyingPig-Shade', 'FlyingPig-Skeleton', 'FlyingPig-Zombie', 'FlyingPig-CottonCandyPink', 'FlyingPig-CottonCandyBlue', 'FlyingPig-Golden', 'Dragon-Base', 'Dragon-White', 'Dragon-Desert', 'Dragon-Red', 'Dragon-Shade', 'Dragon-Skeleton', 'Dragon-Zombie', 'Dragon-CottonCandyPink', 'Dragon-CottonCandyBlue', 'Dragon-Golden', 'Cactus-Base', 'Cactus-White', 'Cactus-Desert', 'Cactus-Red', 'Cactus-Shade', 'Cactus-Skeleton', 'Cactus-Zombie', 'Cactus-CottonCandyPink', 'Cactus-CottonCandyBlue', 'Cactus-Golden', 'BearCub-Base', 'BearCub-White', 'BearCub-Desert', 'BearCub-Red', 'BearCub-Shade', 'BearCub-Skeleton', 'BearCub-Zombie', 'BearCub-CottonCandyPink', 'BearCub-CottonCandyBlue', 'BearCub-Golden']; // all Gen1 mounts
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
let mounts = user.items.mounts;
|
||||
let changed = false;
|
||||
for (let a in animals) {
|
||||
if (mounts[animals[a]] === false) {
|
||||
mounts[animals[a]] = null;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
dbUsers.update(
|
||||
{ _id: user._id},
|
||||
{
|
||||
$set: { migration: migrationName,
|
||||
'items.mounts': mounts,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// var set = {'migration': migrationName};
|
||||
// var inc = {'xyz':1, _v:1};
|
||||
// dbUsers.update({_id:user._id}, {$set:set, $inc:inc});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
if (user._id === '9') console.warn('lefnire' + ' processed');
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
36
migrations/archive/2015/20150130_birthday_goodies.js
Normal file
36
migrations/archive/2015/20150130_birthday_goodies.js
Normal file
@@ -0,0 +1,36 @@
|
||||
db.users.update(
|
||||
{'items.gear.owned.armor_special_birthday': {$ne: null}},
|
||||
{$set: {'items.gear.owned.armor_special_birthday2015': false}},
|
||||
{multi: 1}
|
||||
);
|
||||
|
||||
db.users.update(
|
||||
{'items.gear.owned.armor_special_birthday': null},
|
||||
{$set: {'items.gear.owned.armor_special_birthday': false}},
|
||||
{multi: 1}
|
||||
);
|
||||
|
||||
db.users.update({}, {$inc: {
|
||||
'items.food.Cake_Skeleton': 1,
|
||||
'items.food.Cake_Base': 1,
|
||||
'items.food.Cake_CottonCandyBlue': 1,
|
||||
'items.food.Cake_CottonCandyPink': 1,
|
||||
'items.food.Cake_Shade': 1,
|
||||
'items.food.Cake_White': 1,
|
||||
'items.food.Cake_Golden': 1,
|
||||
'items.food.Cake_Zombie': 1,
|
||||
'items.food.Cake_Desert': 1,
|
||||
'items.food.Cake_Red': 1,
|
||||
}}, {multi: 1});
|
||||
|
||||
db.users.update(
|
||||
{'achievements.habitBirthday': true},
|
||||
{$set: {'achievements.habitBirthdays': 1}},
|
||||
{multi: 1}
|
||||
);
|
||||
|
||||
db.users.update(
|
||||
{},
|
||||
{$inc: {'achievements.habitBirthdays': 1}},
|
||||
{multi: 1}
|
||||
);
|
||||
@@ -0,0 +1,85 @@
|
||||
let migrationName = '20150131_birthday_goodies_fix__one_birthday__1';
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/*
|
||||
* remove new birthday robes and second achievement from people who shouldn't have them
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // CHANGE THIS FOR PRODUCTION DATABASE
|
||||
|
||||
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
||||
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
||||
// adapted to work with it. Before this migration is used again any lodash method should
|
||||
// be checked for compatibility against the v4 changelog and changed if necessary.
|
||||
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/habitrpg?auto_reconnect`).collection('users');
|
||||
|
||||
// 'auth.timestamps.created':{$gt:new Date('2014-02-01')},
|
||||
let query = {
|
||||
'achievements.habitBirthdays': 1,
|
||||
'auth.timestamps.loggedin': {$gt: new Date('2014-12-20')},
|
||||
};
|
||||
|
||||
// '_id': 'c03e41bd-501f-438c-9553-a7afdf52a08c',
|
||||
// 'achievements.habitBirthday':{$exists:false},
|
||||
// 'items.gear.owned.armor_special_birthday2015':1
|
||||
|
||||
let fields = {
|
||||
// 'auth.timestamps.created':1,
|
||||
// 'achievements.habitBirthday':1,
|
||||
// 'achievements.habitBirthdays':1,
|
||||
'items.gear.owned.armor_special_birthday2015': 1,
|
||||
// 'items.gear.owned.armor_special':1
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
let unset = {'items.gear.owned.armor_special_birthday2015': 1};
|
||||
// var set = {'migration':migrationName, 'achievements.habitBirthdays':1 };
|
||||
// var inc = {'xyz':1, _v:1};
|
||||
dbUsers.update({_id: user._id}, {$unset: unset}); // , $inc:inc});
|
||||
// dbUsers.update({_id:user._id}, {$unset:unset, $set:set});
|
||||
// console.warn(user.auth.timestamps.created);
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
if (user._id === '9') console.warn('lefnire' + ' processed');
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
let migrationName = '20150201_convert_creation_date_from_string_to_object__no_date_recent_signup';
|
||||
// // var migrationName = '20150201_convert_creation_date_from_string_to_object';
|
||||
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/*
|
||||
* For users that have no value for auth.timestamps.created, assign them
|
||||
* a recent value.
|
||||
*
|
||||
* NOTE:
|
||||
* Before this script was used as described above, it was first used to
|
||||
* find all users that have a auth.timestamps.created field that is a string
|
||||
* rather than a date object and set it to be a date object. The code used
|
||||
* for this has been commented out with four slashes: ////
|
||||
*
|
||||
* https://github.com/HabitRPG/habitrpg/issues/4601#issuecomment-72339846
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // CHANGE THIS FOR PRODUCTION DATABASE
|
||||
|
||||
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
||||
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
||||
// adapted to work with it. Before this migration is used again any lodash method should
|
||||
// be checked for compatibility against the v4 changelog and changed if necessary.
|
||||
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
let moment = require('moment');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/habitrpg?auto_reconnect`).collection('users');
|
||||
|
||||
let uuidArrayRecent = [ // recent users with no creation dates
|
||||
'1a0d4b75-73ed-4937-974d-d504d6398884',
|
||||
'1c7ebe27-1250-4f95-ba10-965580adbfd7',
|
||||
'5f972121-4a6d-411c-95e9-7093d3e89b66',
|
||||
'ae85818a-e336-4ccd-945e-c15cef975102',
|
||||
'ba273976-d9fc-466c-975f-38559d34a824',
|
||||
];
|
||||
|
||||
let query = {
|
||||
_id: {$in: uuidArrayRecent},
|
||||
// // 'auth':{$exists:true},
|
||||
// // 'auth.timestamps':{$exists:true},
|
||||
// // 'auth.timestamps.created':{$not: {$lt:new Date('2018-01-01')}}
|
||||
};
|
||||
|
||||
let fields = {
|
||||
_id: 1,
|
||||
'auth.timestamps.created': 1,
|
||||
};
|
||||
// 'achievements.habitBirthdays':1
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// // var oldDate = user.auth.timestamps.created;
|
||||
// // var newDate = moment(oldDate).toDate();
|
||||
let oldDate = 'none';
|
||||
let newDate = moment('2015-01-11').toDate();
|
||||
console.warn(`${user._id } === ${ oldDate } === ${ newDate}`);
|
||||
|
||||
// // var set = { 'migration': migrationName,
|
||||
// // 'auth.timestamps.created': newDate,
|
||||
// // 'achievements.habitBirthdays': 2,
|
||||
// // 'items.gear.owned.head_special_nye':true,
|
||||
// // 'items.gear.owned.head_special_nye2014':true,
|
||||
// // 'items.gear.owned.armor_special_birthday':true,
|
||||
// // 'items.gear.owned.armor_special_birthday2015':true,
|
||||
// // };
|
||||
|
||||
let set = { migration: migrationName,
|
||||
'auth.timestamps.created': newDate,
|
||||
'achievements.habitBirthdays': 1,
|
||||
'items.gear.owned.armor_special_birthday': true,
|
||||
};
|
||||
|
||||
// var unset = {'items.gear.owned.armor_special_birthday2015': 1};
|
||||
// var inc = {'xyz':1, _v:1};
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
// dbUsers.update({_id:user._id}, {$unset:unset, $set:set, $inc:inc});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
if (user._id === '9') console.warn('lefnire' + ' processed');
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
db.users.update({
|
||||
'flags.recaptureEmailsPhase': {
|
||||
$gt: 0,
|
||||
},
|
||||
}, {$inc: {
|
||||
'flags.recaptureEmailsPhase': 1,
|
||||
}}, {multi: 1});
|
||||
10
migrations/archive/2015/20150218_interactive_tour.js
Normal file
10
migrations/archive/2015/20150218_interactive_tour.js
Normal file
@@ -0,0 +1,10 @@
|
||||
db.users.update({}, {$set: {
|
||||
'flags.tour.intro': -2,
|
||||
// 'flags.tour.classes':-2,
|
||||
'flags.tour.stats': -2,
|
||||
'flags.tour.tavern': -2,
|
||||
'flags.tour.party': -2,
|
||||
'flags.tour.guilds': -2,
|
||||
'flags.tour.challenges': -2,
|
||||
'flags.tour.market': -2,
|
||||
}}, {multi: 1});
|
||||
71
migrations/archive/2015/20150224_force_resting_in_inn.js
Normal file
71
migrations/archive/2015/20150224_force_resting_in_inn.js
Normal file
@@ -0,0 +1,71 @@
|
||||
let migrationName = '20150224_force_resting_in_inn';
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/*
|
||||
* force all active players to rest in the inn due to massive server fail
|
||||
*/
|
||||
|
||||
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
||||
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
||||
// adapted to work with it. Before this migration is used again any lodash method should
|
||||
// be checked for compatibility against the v4 changelog and changed if necessary.
|
||||
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
||||
|
||||
let dbserver = 'localhost:27017'; // CHANGE THIS FOR PRODUCTION DATABASE
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/habitrpg?auto_reconnect`).collection('users');
|
||||
|
||||
let query = {
|
||||
'auth.timestamps.loggedin': {$gt: new Date('2015-02-22')},
|
||||
};
|
||||
|
||||
let fields = {
|
||||
'preferences.sleep': 1,
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
let set = {migration: migrationName, 'preferences.sleep': 1 };
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
if (user._id === '9') console.warn('lefnire' + ' processed');
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
5
migrations/archive/2015/20150310_survey_achievements.js
Normal file
5
migrations/archive/2015/20150310_survey_achievements.js
Normal file
@@ -0,0 +1,5 @@
|
||||
db.users.update(
|
||||
{'achievements.helpedHabit': true},
|
||||
{$set: {'achievements.habitSurveys': 1}},
|
||||
{multi: 1}
|
||||
);
|
||||
8
migrations/archive/2015/20150325_egg_quest.js
Normal file
8
migrations/archive/2015/20150325_egg_quest.js
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Created by Sabe on 3/25/2015.
|
||||
*/
|
||||
db.users.update(
|
||||
{},
|
||||
{$inc: {'items.quests.egg': 1}},
|
||||
{multi: 1}
|
||||
);
|
||||
141
migrations/archive/2015/20150604_ultimateGearSets.js
Normal file
141
migrations/archive/2015/20150604_ultimateGearSets.js
Normal file
@@ -0,0 +1,141 @@
|
||||
// var migrationName = '20150604_ultimateGearSets';
|
||||
// var authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
// var authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; //... own data is done
|
||||
|
||||
let migrationName = '20150620_ultimateGearSets';
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/*
|
||||
* grant the new ultimateGearSets achievement for existing users' collected equipment
|
||||
*
|
||||
*
|
||||
* Changed by Alys on 20150620 to assign false values to
|
||||
* 'achievements.ultimateGearSets' when true values are not appropriate,
|
||||
* because of https://github.com/HabitRPG/habitrpg/issues/5427
|
||||
*
|
||||
* Minimal changes were made so the code isn't as efficient or clean
|
||||
* as it could be, but it's (hopefully) one-use-only and minimal changes
|
||||
* means minimal new testing.
|
||||
*/
|
||||
|
||||
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
||||
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
||||
// adapted to work with it. Before this migration is used again any lodash method should
|
||||
// be checked for compatibility against the v4 changelog and changed if necessary.
|
||||
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379' // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
let fields = {
|
||||
'achievements.ultimateGearSets': 1,
|
||||
'items.gear.owned': 1,
|
||||
};
|
||||
|
||||
|
||||
// Changes 20150620: All users have to be processed now (non-achievers need
|
||||
// false values).
|
||||
let query = {
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
let achievements = {};
|
||||
let changeUser = false;
|
||||
// Changes 20150620: 'changeUser' now indicates that the user must have the
|
||||
// Enchanted Armoire unlocked.
|
||||
if (typeof user.items.gear.owned.weapon_wizard_6 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.armor_wizard_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.head_wizard_5 !== 'undefined'
|
||||
) {
|
||||
achievements.wizard = true;
|
||||
changeUser = true;
|
||||
} else {
|
||||
// Changes 20150620: false added for all classes (here and below)
|
||||
achievements.wizard = false;
|
||||
}
|
||||
|
||||
if (typeof user.items.gear.owned.weapon_warrior_6 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.armor_warrior_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.head_warrior_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.shield_warrior_5 !== 'undefined'
|
||||
) {
|
||||
achievements.warrior = true;
|
||||
changeUser = true;
|
||||
} else {
|
||||
achievements.warrior = false;
|
||||
}
|
||||
|
||||
if (typeof user.items.gear.owned.weapon_healer_6 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.armor_healer_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.head_healer_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.shield_healer_5 !== 'undefined'
|
||||
) {
|
||||
achievements.healer = true;
|
||||
changeUser = true;
|
||||
} else {
|
||||
achievements.healer = false;
|
||||
}
|
||||
|
||||
if (typeof user.items.gear.owned.weapon_rogue_6 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.armor_rogue_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.head_rogue_5 !== 'undefined' &&
|
||||
typeof user.items.gear.owned.shield_rogue_6 !== 'undefined'
|
||||
) {
|
||||
achievements.rogue = true;
|
||||
changeUser = true;
|
||||
} else {
|
||||
achievements.rogue = false;
|
||||
}
|
||||
|
||||
// Changes 20150620: $set is now run for all users.
|
||||
let set = {migration: migrationName, 'achievements.ultimateGearSets': achievements};
|
||||
if (changeUser) { // user has at least one Ultimate Gear achievement
|
||||
set['flags.armoireEnabled'] = true;
|
||||
}
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
if (user._id === '9') console.warn('lefnire' + ' processed');
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
8
migrations/archive/2015/20150706_orca_mounts.js
Normal file
8
migrations/archive/2015/20150706_orca_mounts.js
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Created by Sabe on 7/6/2015.
|
||||
*/
|
||||
db.users.update(
|
||||
{},
|
||||
{$set: {'items.mounts.Orca-Base': true}},
|
||||
{multi: true}
|
||||
);
|
||||
5
migrations/archive/2015/20150731_purple_gryphon.js
Normal file
5
migrations/archive/2015/20150731_purple_gryphon.js
Normal file
@@ -0,0 +1,5 @@
|
||||
db.users.update(
|
||||
{},
|
||||
{$set: {'items.mounts.Gryphon-RoyalPurple': true}},
|
||||
{multi: true}
|
||||
);
|
||||
5
migrations/archive/2015/20150731_veteran_tiger.js
Normal file
5
migrations/archive/2015/20150731_veteran_tiger.js
Normal file
@@ -0,0 +1,5 @@
|
||||
db.users.update(
|
||||
{'items.pets.Wolf-Veteran': {$ne: null}},
|
||||
{$set: {'items.pets.Tiger-Veteran': 5}},
|
||||
{multi: true}
|
||||
);
|
||||
7
migrations/archive/2015/20150731_veteran_wolf.js
Normal file
7
migrations/archive/2015/20150731_veteran_wolf.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// Run after the Veteran Tiger script, not before!
|
||||
|
||||
db.users.update(
|
||||
{'items.pets.Wolf-Veteran': {$exists: false}},
|
||||
{$set: {'items.pets.Wolf-Veteran': 5}},
|
||||
{multi: true}
|
||||
);
|
||||
79
migrations/archive/2015/20150906_groups_fix_leaders.js
Normal file
79
migrations/archive/2015/20150906_groups_fix_leaders.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Make sure leaders are existing users
|
||||
*/
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let async = require('async');
|
||||
|
||||
let dbserver = 'url';
|
||||
let dbname = 'dbname';
|
||||
let countGroups = 0;
|
||||
let countUsers = 0;
|
||||
|
||||
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
||||
let dbUsers = db.collection('users');
|
||||
let dbGroups = db.collection('groups');
|
||||
|
||||
console.log('Begins work on db');
|
||||
|
||||
function findGroups (gt) {
|
||||
let query = {};
|
||||
if (gt) query._id = {$gt: gt};
|
||||
|
||||
console.log(query);
|
||||
|
||||
dbGroups.find(query, {
|
||||
fields: {_id: 1, members: 1, leader: 1},
|
||||
limit: 10000,
|
||||
sort: {
|
||||
_id: 1,
|
||||
},
|
||||
}).toArray(function (err, groups) {
|
||||
if (err) throw err;
|
||||
|
||||
let lastGroup = null;
|
||||
if (groups.length === 10000) {
|
||||
lastGroup = groups[groups.length - 1];
|
||||
}
|
||||
|
||||
async.eachLimit(groups, 30, function (group, cb1) {
|
||||
countGroups++;
|
||||
console.log('Group: ', countGroups, group._id);
|
||||
|
||||
let members = group.members;
|
||||
|
||||
dbUsers.findOne({_id: group.leader}, {fields: {_id: 1}}, function (err, user) {
|
||||
if (err) return cb1(err);
|
||||
|
||||
// If leader has deleted account
|
||||
if (!user && group._id !== 'habitrpg' && members && members[0]) {
|
||||
dbGroups.update({
|
||||
_id: group._id,
|
||||
}, {
|
||||
$set: {
|
||||
// Set first user as new leader
|
||||
leader: members[0],
|
||||
},
|
||||
}, {
|
||||
multi: false,
|
||||
}, function (err, res) {
|
||||
if (err) return cb1(err);
|
||||
|
||||
console.log('Updated: ', res);
|
||||
return cb1();
|
||||
});
|
||||
} else {
|
||||
return cb1();
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
if (lastGroup && lastGroup._id) {
|
||||
findGroups(lastGroup._id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
findGroups();
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Remove deleted accounts from groups
|
||||
*/
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let async = require('async');
|
||||
|
||||
let dbserver = 'url';
|
||||
let dbname = 'dbname';
|
||||
let countGroups = 0;
|
||||
let countUsers = 0;
|
||||
|
||||
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
||||
let dbUsers = db.collection('users');
|
||||
let dbGroups = db.collection('groups');
|
||||
|
||||
console.log('Begins work on db');
|
||||
|
||||
function findGroups (gt) {
|
||||
let query = {};
|
||||
if (gt) query._id = {$gt: gt};
|
||||
|
||||
console.log(query);
|
||||
|
||||
dbGroups.find(query, {
|
||||
fields: {_id: 1, members: 1},
|
||||
limit: 10000,
|
||||
sort: {
|
||||
_id: 1,
|
||||
},
|
||||
}).toArray(function (err, groups) {
|
||||
if (err) throw err;
|
||||
|
||||
let lastGroup = null;
|
||||
if (groups.length === 10000) {
|
||||
lastGroup = groups[groups.length - 1];
|
||||
}
|
||||
|
||||
async.eachLimit(groups, 3, function (group, cb1) {
|
||||
countGroups++;
|
||||
console.log('Group: ', countGroups, group._id);
|
||||
|
||||
let members = group.members;
|
||||
|
||||
// Remove users who deleted their account
|
||||
async.eachLimit(members, 15, function (member, cb2) {
|
||||
dbUsers.findOne({_id: member}, {fields: {_id: 1}}, function (err, user) {
|
||||
if (err) return cb2(err);
|
||||
|
||||
if (!user) {
|
||||
countUsers++;
|
||||
console.log('User removed n. ', countUsers, 'user id ', member, 'group id ', group._id);
|
||||
|
||||
dbGroups.update({
|
||||
_id: group._id,
|
||||
}, {
|
||||
$pull: {members: member},
|
||||
$inc: {memberCount: -1},
|
||||
}, {
|
||||
multi: false,
|
||||
}, function (err, res) {
|
||||
if (err) return cb2(err);
|
||||
|
||||
console.log('Updated: ', res);
|
||||
return cb2();
|
||||
});
|
||||
} else {
|
||||
cb2();
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) return cb1(err);
|
||||
|
||||
cb1();
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
if (lastGroup && lastGroup._id) {
|
||||
findGroups(lastGroup._id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
findGroups();
|
||||
21
migrations/archive/2015/20150906_groups_remove_empty.js
Normal file
21
migrations/archive/2015/20150906_groups_remove_empty.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Remove empty private groups
|
||||
*/
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
|
||||
let dbserver = 'url';
|
||||
let dbname = 'name';
|
||||
|
||||
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
||||
let dbGroups = db.collection('groups');
|
||||
|
||||
console.log('Begins work on db');
|
||||
|
||||
dbGroups.findEach({
|
||||
memberCount: 0,
|
||||
}, {_id: 1}, function (err, res) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log(res);
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Sync groups with Firebase
|
||||
*/
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let Firebase = require('Firebase');
|
||||
|
||||
let dbserver = 'mongodb://url';
|
||||
let dbname = 'db';
|
||||
|
||||
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
||||
let dbGroups = db.collection('groups');
|
||||
let countGroups = 0;
|
||||
|
||||
let firebaseRef = new Firebase('https://' + 'firebase-app' + '.firebaseio.com');
|
||||
|
||||
// TODO handle sync errors with firebase?
|
||||
firebaseRef.authWithCustomToken('firebase-secret', function (err, authData) {
|
||||
if (err) throw new Error('Impossible to authenticate Firebase');
|
||||
|
||||
console.log('Firebase connected, begins work on db');
|
||||
|
||||
dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 100}, function (err, group) {
|
||||
if (err) throw err;
|
||||
if (group._id !== 'habitrpg') return;
|
||||
|
||||
countGroups++;
|
||||
console.log('Group: ', countGroups);
|
||||
|
||||
firebaseRef.child(`rooms/${ group._id}`)
|
||||
.set({
|
||||
name: group.name,
|
||||
});
|
||||
|
||||
group.members.forEach(function (member) {
|
||||
firebaseRef.child(`members/${ group._id }/${ userId}`)
|
||||
.set(true);
|
||||
|
||||
firebaseRef.child(`users/${ member }/rooms/${ group._id}`)
|
||||
.set(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
74
migrations/archive/2015/20151013_jackolanterns.js
Normal file
74
migrations/archive/2015/20151013_jackolanterns.js
Normal file
@@ -0,0 +1,74 @@
|
||||
let migrationName = '20151013_jackolanterns.js';
|
||||
let authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
let authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done
|
||||
|
||||
/*
|
||||
* Award Jack-O'-Lantern mounts to users who already have the pet version, award pet if they don't
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
// specify a query to limit the affected users (empty for all users):
|
||||
let query = {
|
||||
};
|
||||
|
||||
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||
let fields = {
|
||||
'items.pets.JackOLantern-Base': 1,
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// specify user data to change:
|
||||
let set = {};
|
||||
if (user.items.pets['JackOLantern-Base']) {
|
||||
set = {migration: migrationName, 'items.mounts.JackOLantern-Base': true};
|
||||
} else {
|
||||
set = {migration: migrationName, 'items.pets.JackOLantern-Base': 5};
|
||||
}
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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();
|
||||
70
migrations/archive/2015/20151105_tutorial_flags.js
Normal file
70
migrations/archive/2015/20151105_tutorial_flags.js
Normal file
@@ -0,0 +1,70 @@
|
||||
let migrationName = '20151105_tutorial_flags_v1';
|
||||
let authorName = 'Alys'; // in case script author needs to know when their ...
|
||||
let authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; // ... own data is done
|
||||
|
||||
/*
|
||||
* set flags.tutorial.ios and flags.tutorial.main flags to true in preparation
|
||||
* for the release of a new iOS tutorial
|
||||
*
|
||||
*/
|
||||
|
||||
// var dbserver = 'localhost:27017' // FOR TEST DATABASE
|
||||
let dbserver = 'alys:@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
let fields = {
|
||||
};
|
||||
|
||||
|
||||
let query = {
|
||||
'auth.timestamps.loggedin': {$gt: new Date('2015-10-20')},
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// var set = {'migration':migrationName, 'flags.tutorial.ios':true, 'flags.tutorial.main':true };
|
||||
let set = {migration: migrationName, 'flags.tutorial.ios': {} };
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
109
migrations/archive/2015/20151116_costume_contest_award.js
Normal file
109
migrations/archive/2015/20151116_costume_contest_award.js
Normal file
@@ -0,0 +1,109 @@
|
||||
let migrationName = '20151116_costume_contest.js';
|
||||
let authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
let authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done
|
||||
|
||||
/*
|
||||
* Award Costume Contest achievement to 2015 winners
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
// specify a query to limit the affected users (empty for all users):
|
||||
let query = {
|
||||
_id: {
|
||||
$in: [
|
||||
'e411dab3-a4ca-414d-bdbd-b6940b3bdeb3',
|
||||
'35ced5cc-c33a-45c8-93dc-16000ee66fde',
|
||||
'ab3f0549-7247-4fd5-975b-efcff98c79c3',
|
||||
'b1261fd2-eb25-46b4-97a9-ae7a0dc8a131',
|
||||
'1f27893f-3808-4724-9725-f46dab93faca',
|
||||
'216a0c23-6afd-4a5e-b434-d386a10862a2',
|
||||
'2d6ef231-50b4-4a22-90e7-45eb97147a2c',
|
||||
'98b8cf4f-89bd-4b0a-988d-02629a217232',
|
||||
'c5183dfa-c741-43ce-935e-c6d89b41a030',
|
||||
'262a7afb-6b57-4d81-88e0-80d2e9f6cbdc',
|
||||
'33991e0a-de55-4986-ac81-af78491a84de',
|
||||
'7adf6ada-3c05-4054-b5df-fa7d49d3b9eb',
|
||||
'235a1cbd-48c5-41b1-afb4-59d2f8645c57',
|
||||
'b7617a61-188b-4332-bf4d-32268fa77f2b',
|
||||
'672c1ce0-9f47-44f0-a3f3-8cc3c6c5a9cb',
|
||||
'd0a3217a-7b92-48d6-b39a-b1b1be96702e',
|
||||
'5ef910dc-1d22-47d9-aa38-a60132c60679',
|
||||
'370a44c8-e94a-4a2c-91f2-33166926db1f',
|
||||
'1b0b3ef3-28bd-4046-a49b-e1c83e281baf',
|
||||
'75b93321-66b9-49bd-9076-052499c1d2bf',
|
||||
'd97516e4-81d0-4f60-bf03-95f7330925ab',
|
||||
'3e13cc79-de38-420d-822e-9e9da309ce6b',
|
||||
'0e471dc1-ecb0-4388-a891-b873a237d2cf',
|
||||
'ca3da398-4f73-4304-b838-af3669ed4cbb',
|
||||
'44cdf105-8bda-4197-9d1a-1bcb83b4dc84',
|
||||
'5419830c-b837-4573-ae82-4718ab95b7f1',
|
||||
'ac6fbe37-b0dc-40d8-ba14-77dde66fbfa8',
|
||||
'8789ba18-a498-46b9-b367-3b929a0acb94',
|
||||
'52fce1a9-9b0a-4e26-95dc-adc12f52e752',
|
||||
'21bf71ac-399c-470b-abe0-cc49a03b6a8b',
|
||||
'f1618ce2-552e-4f23-bc76-e73d63ebedd0',
|
||||
'4cc0c749-d943-4090-b529-42bc665b7244',
|
||||
'e259682e-cb5c-4d94-b472-ceedc66d7484',
|
||||
'fa197a4b-e065-4551-803a-c8a5b9970f9d',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||
let fields = {
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// specify user data to change:
|
||||
let set = {migration: migrationName};
|
||||
let inc = {'achievements.costumeContests': 1};
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
dbUsers.update({_id: user._id}, {$inc: inc});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
let migrationName = '20151116_costume_contest_to_number.js';
|
||||
let authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
let authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done
|
||||
|
||||
/*
|
||||
* Change Costume Contest achievement from Boolean to Number, so people can win repeatedly
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
// specify a query to limit the affected users (empty for all users):
|
||||
let query = {
|
||||
'achievements.costumeContest': true,
|
||||
};
|
||||
|
||||
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||
let fields = {
|
||||
'achievements.costumeContest': 1,
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// specify user data to change:
|
||||
let set = {'achievements.costumeContests': 1};
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
|
||||
78
migrations/archive/2015/20151125_turkey_ladder.js
Normal file
78
migrations/archive/2015/20151125_turkey_ladder.js
Normal file
@@ -0,0 +1,78 @@
|
||||
let migrationName = '20151125_turkey_ladder.js';
|
||||
let authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
let authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done
|
||||
|
||||
/*
|
||||
* Award Gilded Turkey pet to Turkey mount owners, Turkey Mount if they only have Turkey Pet,
|
||||
* and Turkey Pet otherwise
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
// specify a query to limit the affected users (empty for all users):
|
||||
let query = {
|
||||
};
|
||||
|
||||
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||
let fields = {
|
||||
'items.pets.Turkey-Base': 1,
|
||||
'items.mounts.Turkey-Base': 1,
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// specify user data to change:
|
||||
let set = {};
|
||||
if (user.items.mounts['Turkey-Base']) {
|
||||
set = {migration: migrationName, 'items.pets.Turkey-Gilded': 5};
|
||||
} else if (user.items.pets['Turkey-Base']) {
|
||||
set = {migration: migrationName, 'items.mounts.Turkey-Base': true};
|
||||
} else {
|
||||
set = {migration: migrationName, 'items.pets.Turkey-Base': 5};
|
||||
}
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
77
migrations/archive/2015/20151229_new_years_hats.js
Normal file
77
migrations/archive/2015/20151229_new_years_hats.js
Normal file
@@ -0,0 +1,77 @@
|
||||
let migrationName = '20151229_new_years_hats.js';
|
||||
let authorName = 'Sabe'; // in case script author needs to know when their ...
|
||||
let authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done
|
||||
|
||||
/*
|
||||
* Award 2015 party hat if user has 2014 hat, 2014 hat if they have the 2013 hat,
|
||||
* and 2013 hat otherwise
|
||||
*/
|
||||
|
||||
let dbserver = 'localhost:27017'; // FOR TEST DATABASE
|
||||
// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE
|
||||
let dbname = 'habitrpg';
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let _ = require('lodash');
|
||||
|
||||
let dbUsers = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`).collection('users');
|
||||
|
||||
// specify a query to limit the affected users (empty for all users):
|
||||
let query = {
|
||||
};
|
||||
|
||||
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||
let fields = {
|
||||
'items.gear.owned': 1,
|
||||
};
|
||||
|
||||
console.warn('Updating users...');
|
||||
let progressCount = 1000;
|
||||
let count = 0;
|
||||
dbUsers.findEach(query, fields, {batchSize: 250}, function (err, user) {
|
||||
if (err) {
|
||||
return exiting(1, `ERROR! ${ err}`);
|
||||
}
|
||||
if (!user) {
|
||||
console.warn('All appropriate users found and modified.');
|
||||
return displayData();
|
||||
}
|
||||
count++;
|
||||
|
||||
// specify user data to change:
|
||||
let set = {};
|
||||
if (user.items && user.items.gear && user.items.gear.owned && user.items.gear.owned.hasOwnProperty('head_special_nye2014')) {
|
||||
set = {migration: migrationName, 'items.gear.owned.head_special_nye2015': false};
|
||||
} else if (user.items && user.items.gear && user.items.gear.owned && user.items.gear.owned.hasOwnProperty('head_special_nye')) {
|
||||
set = {migration: migrationName, 'items.gear.owned.head_special_nye2014': false};
|
||||
} else {
|
||||
set = {migration: migrationName, 'items.gear.owned.head_special_nye': false};
|
||||
}
|
||||
|
||||
dbUsers.update({_id: user._id}, {$set: set});
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
|
||||
if (user._id === authorUuid) console.warn(`${authorName } processed`);
|
||||
});
|
||||
|
||||
|
||||
function displayData () {
|
||||
console.warn(`\n${ count } users processed\n`);
|
||||
return exiting(0);
|
||||
}
|
||||
|
||||
|
||||
function exiting (code, msg) {
|
||||
code = code || 0; // 0 = success
|
||||
if (code && !msg) {
|
||||
msg = 'ERROR!';
|
||||
}
|
||||
if (msg) {
|
||||
if (code) {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
process.exit(code);
|
||||
}
|
||||
Reference in New Issue
Block a user