diff --git a/migrations/20160731_naming_day.js b/migrations/20160731_naming_day.js new file mode 100644 index 0000000000..601798d14c --- /dev/null +++ b/migrations/20160731_naming_day.js @@ -0,0 +1,82 @@ +var migrationName = '20160731_naming_day.js'; +var authorName = 'Sabe'; // in case script author needs to know when their ... +var authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; //... own data is done + +/* + * Award Royal Purple Gryphon pet to Royal Purple Gryphon mount owners, mount to everyone else + */ + +var mongo = require('mongoskin'); + +var connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE + +var dbUsers = mongo.db(connectionString).collection('users'); + +// specify a query to limit the affected users (empty for all users): +var query = { + 'migration':{$ne:migrationName}, + 'auth.timestamps.loggedin':{$gt:new Date('2016-07-30')} // Extend timeframe each run of migration +}; + +// specify fields we are interested in to limit retrieved data (empty if we're not reading data): +var fields = { + 'items.mounts': 1 +}; + +console.warn('Updating users...'); +var progressCount = 1000; +var 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.'); + setTimeout(displayData, 300000); + return; + } + count++; + + // specify user data to change: + var set = {}; + var inc = {}; + inc = { + 'achievements.habiticaDays': 1, + '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 + }; + if (user.items.mounts['Gryphon-RoyalPurple']) { + set = {'migration':migrationName, 'items.pets.Gryphon-RoyalPurple':5}; + } else { + set = {'migration':migrationName, 'items.mounts.Gryphon-RoyalPurple':true}; + } + + 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'); +}); + + +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); +} + diff --git a/migrations/20160731_takeThis.js b/migrations/20160731_takeThis.js new file mode 100644 index 0000000000..b08700a4bd --- /dev/null +++ b/migrations/20160731_takeThis.js @@ -0,0 +1,71 @@ +var migrationName = '20160731_takeThis.js'; +var authorName = 'Sabe'; // in case script author needs to know when their ... +var authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; //... own data is done + +/* + * Award Take This Sword to Take This challenge participants who already own the Shield + * and Take This Shield to the rest of the list + */ + +var mongo = require('mongoskin'); + +var connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE + +var dbUsers = mongo.db(connectionString).collection('users'); + +// specify a query to limit the affected users (empty for all users): +var query = { + 'migration':{$ne:migrationName}, + 'auth.timestamps.loggedin':{$gt:new Date('2016-07-30')}, // Extend timeframe each run of migration + 'challenges':{$in:['da8859b2-5c6e-4aa5-b8b2-8db93d5de9fc']} +}; + +// specify fields we are interested in to limit retrieved data (empty if we're not reading data): +var fields = { + 'items.gear.owned': 1 +}; + +console.warn('Updating users...'); +var progressCount = 1000; +var 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.'); + setTimeout(displayData, 300000); + return; + } + count++; + + // specify user data to change: + var set = {}; + + if (typeof user.items.gear.owned.shield_special_takeThis !== 'undefined') { + set = {'migration':migrationName, 'items.gear.owned.weapon_special_takeThis':false}; + } else { + set = {'migration':migrationName, 'items.gear.owned.shield_special_takeThis':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); +} + diff --git a/migrations/new_stuff.js b/migrations/new_stuff.js index 9d8b796c69..4fcb2e6ac7 100644 --- a/migrations/new_stuff.js +++ b/migrations/new_stuff.js @@ -6,23 +6,19 @@ var authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; //... own data is done * set the newStuff flag in all user accounts so they see a Bailey message */ -var dbserver = 'localhost:27017'; // FOR TEST DATABASE -// var dbserver = 'username:password@ds031379-a0.mongolab.com:31379'; // FOR PRODUCTION DATABASE -var dbname = 'habitrpg'; - var mongo = require('mongoskin'); -var _ = require('lodash'); -var dbUsers = mongo.db(dbserver + '/' + dbname + '?auto_reconnect').collection('users'); +var connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE + +var dbUsers = mongo.db(connectionString).collection('users'); // specify a query to limit the affected users (empty for all users): var query = { - 'flags.newStuff':false + 'flags.newStuff':{$ne:true} }; // specify fields we are interested in to limit retrieved data (empty if we're not reading data): var fields = { - 'flags.newStuff':1 }; console.warn('Updating users...'); @@ -32,7 +28,8 @@ 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(); + setTimeout(displayData, 300000); + return; } count++; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index e22267f1b2..267e35fab9 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -5949,11 +5949,6 @@ } } }, - "kerberos": { - "version": "0.0.3", - "from": "kerberos@0.0.3", - "resolved": "https://registry.npmjs.org/kerberos/-/kerberos-0.0.3.tgz" - }, "kew": { "version": "0.7.0", "from": "kew@>=0.7.0 <0.8.0", diff --git a/package.json b/package.json index c78b1bcca5..49d40852d6 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,7 @@ "lcov-result-merger": "^1.0.2", "mocha": "^2.3.3", "mongodb": "^2.0.46", - "mongoskin": "~0.6.1", + "mongoskin": "~2.1.0", "nock": "^2.17.0", "phantomjs": "^1.9", "protractor": "^3.1.1",