mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Naming Day and Take This migrations (#7838)
* feat(migrations): Naming Day and Take This * fix(migration): more goodies, better query * fix(migration): query in wrong migration * fix(migration): don't award goodies repeatedly * fix(migrations): move logic to query * fix(migrations): better field lookup * fix(migrations): use timeouts
This commit is contained in:
82
migrations/20160731_naming_day.js
Normal file
82
migrations/20160731_naming_day.js
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
71
migrations/20160731_takeThis.js
Normal file
71
migrations/20160731_takeThis.js
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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
|
* 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 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):
|
// specify a query to limit the affected users (empty for all users):
|
||||||
var query = {
|
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):
|
// specify fields we are interested in to limit retrieved data (empty if we're not reading data):
|
||||||
var fields = {
|
var fields = {
|
||||||
'flags.newStuff':1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.warn('Updating users...');
|
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 (err) { return exiting(1, 'ERROR! ' + err); }
|
||||||
if (!user) {
|
if (!user) {
|
||||||
console.warn('All appropriate users found and modified.');
|
console.warn('All appropriate users found and modified.');
|
||||||
return displayData();
|
setTimeout(displayData, 300000);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
|
|||||||
5
npm-shrinkwrap.json
generated
5
npm-shrinkwrap.json
generated
@@ -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": {
|
"kew": {
|
||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"from": "kew@>=0.7.0 <0.8.0",
|
"from": "kew@>=0.7.0 <0.8.0",
|
||||||
|
|||||||
@@ -148,7 +148,7 @@
|
|||||||
"lcov-result-merger": "^1.0.2",
|
"lcov-result-merger": "^1.0.2",
|
||||||
"mocha": "^2.3.3",
|
"mocha": "^2.3.3",
|
||||||
"mongodb": "^2.0.46",
|
"mongodb": "^2.0.46",
|
||||||
"mongoskin": "~0.6.1",
|
"mongoskin": "~2.1.0",
|
||||||
"nock": "^2.17.0",
|
"nock": "^2.17.0",
|
||||||
"phantomjs": "^1.9",
|
"phantomjs": "^1.9",
|
||||||
"protractor": "^3.1.1",
|
"protractor": "^3.1.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user