mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
v3: more verbose logging in production and fix migration bugs
This commit is contained in:
@@ -95,7 +95,7 @@ function processChallenges (afterId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
promises.push(newUserCollection.updateMany({
|
promises.push(newUserCollection.updateMany({
|
||||||
_id: {$in: oldChallenge.members},
|
_id: {$in: oldChallenge.members || []},
|
||||||
}, {
|
}, {
|
||||||
$push: {challenges: oldChallenge._id},
|
$push: {challenges: oldChallenge._id},
|
||||||
}, {multi: true}));
|
}, {multi: true}));
|
||||||
|
|||||||
@@ -102,9 +102,11 @@ function processGroups (afterId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldGroups.forEach(function (oldGroup) {
|
oldGroups.forEach(function (oldGroup) {
|
||||||
if ((!oldGroup.privacy || oldGroup.privacy === 'private') && (!oldGroup.members || oldGroup.members.length === 0)) return; // delete empty private groups
|
if ((!oldGroup.privacy || oldGroup.privacy === 'private') && (!oldGroup.members || oldGroup.members.length === 0)) return; // delete empty private groups TODO must also delete challenges or this won't work
|
||||||
|
|
||||||
|
oldGroup.members = oldGroup.members || [];
|
||||||
oldGroup.memberCount = oldGroup.members ? oldGroup.members.length : 0;
|
oldGroup.memberCount = oldGroup.members ? oldGroup.members.length : 0;
|
||||||
oldGroup.memberCount = oldGroup.challenges ? oldGroup.challenges.length : 0;
|
oldGroup.challengeCount = oldGroup.challenges ? oldGroup.challenges.length : 0;
|
||||||
|
|
||||||
if (!oldGroup.balance <= 0) oldGroup.balance = 0;
|
if (!oldGroup.balance <= 0) oldGroup.balance = 0;
|
||||||
if (!oldGroup.name) oldGroup.name = 'group name';
|
if (!oldGroup.name) oldGroup.name = 'group name';
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
DEFINE BEFORE MIGRATING
|
DEFINE BEFORE MIGRATING
|
||||||
|
|
||||||
tasks: userId (sparse?), challenge.id (sparse), challenge.taskId (sparse), type? completed?
|
tasks: userId OK (sparse?), challenge.id OK (sparse?), challenge.taskId OK (sparse?), type? completed?
|
||||||
users:
|
users:
|
||||||
id & apiToken?,
|
id & apiToken, OK
|
||||||
auth.facebook.emails.value -> unique and sparse?,
|
auth.facebook.emails.value OK -> unique and sparse?,
|
||||||
auth.facebook.id - unique and sparse,
|
auth.facebook.id - unique and sparse, OK
|
||||||
auth.local.email - unique and sparse,
|
auth.local.email - unique and sparse, OK
|
||||||
auth.local.lowerCaseUsername,
|
auth.local.lowerCaseUsername, OK
|
||||||
auth.local.username - unique and sparse
|
auth.local.username - unique OK
|
||||||
auth.local.username & auth.local.hashed_password?,
|
auth.local.username & auth.local.hashed_password?,
|
||||||
auth.timestamps.created?,
|
auth.timestamps.created?, OK
|
||||||
auth.timestamps.loggedin?,
|
auth.timestamps.loggedin?, OK
|
||||||
backer.tier -1
|
backer.tier -1 OK
|
||||||
{ "contributor.admin" : 1 , "contributor.level" : -1 , "backer.npc" : -1 , "profile.name" : 1}
|
{ "contributor.admin" : 1 , "contributor.level" : -1 , "backer.npc" : -1 , "profile.name" : 1}
|
||||||
{ "contributor.admin" : 1.0}
|
{ "contributor.admin" : 1.0} NO, see ^
|
||||||
{ "contributor.level" : 1.0}
|
{ "contributor.level" : 1.0} OK
|
||||||
{ "contributor.level" : 1.0 , "purchased.plan.customerId" : 1.0} ?
|
{ "contributor.level" : 1.0 , "purchased.plan.customerId" : 1.0} ?
|
||||||
{ "flags.lastWeeklyRecap" : 1 , "_id" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "preferences.emailNotifications.weeklyRecaps" : 1}
|
NO { "flags.lastWeeklyRecap" : 1 , "_id" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "preferences.emailNotifications.weeklyRecaps" : 1}
|
||||||
{ "invitations.guilds.id" : 1}
|
{ "invitations.guilds.id" : 1} OK
|
||||||
{ "invitations.party.id" : 1}
|
{ "invitations.party.id" : 1} OK
|
||||||
{ "preferences.sleep" : 1 , "_id" : 1 , "flags.lastWeeklyRecap" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "preferences.emailNotifications.weeklyRecaps" : 1}
|
OK { "preferences.sleep" : 1 , "_id" : 1 , "flags.lastWeeklyRecap" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "preferences.emailNotifications.weeklyRecaps" : 1}
|
||||||
{ "preferences.sleep" : 1 , "_id" : 1 , "lastCron" : 1 , "preferences.emailNotifications.importantAnnouncements" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "flags.recaptureEmailsPhase" : 1}
|
OK { "preferences.sleep" : 1 , "_id" : 1 , "lastCron" : 1 , "preferences.emailNotifications.importantAnnouncements" : 1 , "preferences.emailNotifications.unsubscribeFromAll" : 1 , "flags.recaptureEmailsPhase" : 1}
|
||||||
profile.name ?
|
profile.name ? OK
|
||||||
{ "purchased.plan.customerId" : 1.0}
|
{ "purchased.plan.customerId" : 1.0} OK
|
||||||
{ "purchased.plan.paymentMethod" : 1.0}
|
{ "purchased.plan.paymentMethod" : 1.0} OK
|
||||||
|
|
||||||
guilds
|
guilds OK
|
||||||
party.id
|
party.id OK
|
||||||
challenges
|
challenges OK
|
||||||
challenges:
|
challenges:
|
||||||
{ "_id" : 1.0 , "__v" : 1.0} ?
|
{ "_id" : 1.0 , "__v" : 1.0} ? NO
|
||||||
{ "_id" : 1.0 , "official" : -1.0 , "timestamp" : -1.0}
|
{ "_id" : 1.0 , "official" : -1.0 , "timestamp" : -1.0}
|
||||||
{ "group" : 1.0 , "official" : -1.0 , "timestamp" : -1.0}
|
{ "group" : 1.0 , "official" : -1.0 , "timestamp" : -1.0} OK
|
||||||
{ "leader" : 1.0 , "official" : -1.0 , "timestamp" : -1.0}
|
{ "leader" : 1.0 , "official" : -1.0 , "timestamp" : -1.0} OK
|
||||||
{ "members" : 1.0 , "official" : -1.0 , "timestamp" : -1.0} ?
|
{ "members" : 1.0 , "official" : -1.0 , "timestamp" : -1.0} ? NO
|
||||||
{ "official" : -1 , "timestamp" : -1}
|
{ "official" : -1 , "timestamp" : -1} ?
|
||||||
{ "official" : -1 , "timestamp" : -1, "_id": 1} ?
|
{ "official" : -1 , "timestamp" : -1, "_id": 1} ?
|
||||||
groups:
|
groups:
|
||||||
{ "_id" : 1 , "quest.key" : 1}
|
{ "_id" : 1 , "quest.key" : 1} ?
|
||||||
{ "_id" : 1.0 , "__v" : 1.0} ?
|
{ "_id" : 1.0 , "__v" : 1.0} ?
|
||||||
{ "_id" : 1.0 , "privacy" : 1.0 , "members" : 1.0} ?
|
{ "_id" : 1.0 , "privacy" : 1.0 , "members" : 1.0} ? NO
|
||||||
{ "members" : 1.0 , "type" : 1.0 , "memberCount" : -1.0} ?
|
{ "members" : 1.0 , "type" : 1.0 , "memberCount" : -1.0} ? NO
|
||||||
{ "members" : 1} ?
|
{ "members" : 1} ? NO
|
||||||
{ "privacy" : 1.0 , "memberCount" : -1.0} ?
|
{ "privacy" : 1.0 , "memberCount" : -1.0} ?
|
||||||
{ "privacy" : 1.0} ?
|
{ "privacy" : 1.0} OK
|
||||||
{ "type" : 1 , "privacy" : 1} ?
|
{ "type" : 1 , "privacy" : 1} ?
|
||||||
{ "type" : 1.0 , "members" : 1.0} ?
|
{ "type" : 1.0 , "members" : 1.0} ? NO
|
||||||
{ "type" : 1} ?
|
{ "type" : 1} ? OK
|
||||||
emailUnsubscriptions: email unique
|
emailUnsubscriptions: email unique OK
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ function processUsers (afterId) {
|
|||||||
newUser.tasksOrder[`${oldTask.type}s`].push(oldTask._id);
|
newUser.tasksOrder[`${oldTask.type}s`].push(oldTask._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
var allTasksFields = ['_id', 'type', 'text', 'notes', 'tags', 'value', 'priority', 'attribute', 'challenge', 'reminders'];
|
var allTasksFields = ['_id', 'type', 'text', 'notes', 'tags', 'value', 'priority', 'attribute', 'challenge', 'reminders', 'userId', 'legacyId'];
|
||||||
// using mongoose models is too slow
|
// using mongoose models is too slow
|
||||||
if (oldTask.type === 'habit') {
|
if (oldTask.type === 'habit') {
|
||||||
oldTask = _.pick(oldTask, allTasksFields.concat(['history', 'up', 'down']));
|
oldTask = _.pick(oldTask, allTasksFields.concat(['history', 'up', 'down']));
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ if (nconf.get('LOGGLY:enabled')){
|
|||||||
|
|
||||||
if (!logger) {
|
if (!logger) {
|
||||||
logger = new (winston.Logger)({});
|
logger = new (winston.Logger)({});
|
||||||
|
logger.add(winston.transports.Console, {colorize:true}); // TODO remove
|
||||||
|
|
||||||
if (nconf.get('NODE_ENV') !== 'production') {
|
if (nconf.get('NODE_ENV') !== 'production') {
|
||||||
logger.add(winston.transports.Console, {colorize:true});
|
|
||||||
logger.add(winston.transports.File, {filename: 'habitrpg.log'});
|
logger.add(winston.transports.File, {filename: 'habitrpg.log'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ const logger = new winston.Logger();
|
|||||||
if (IS_PROD) {
|
if (IS_PROD) {
|
||||||
// TODO production logging, use loggly and new relic too
|
// TODO production logging, use loggly and new relic too
|
||||||
// log errors to console too
|
// log errors to console too
|
||||||
|
logger
|
||||||
|
.add(winston.transports.Console, {
|
||||||
|
colorize: true,
|
||||||
|
prettyPrint: true,
|
||||||
|
});
|
||||||
} else if (IS_TEST) {
|
} else if (IS_TEST) {
|
||||||
// Do not log anything when testing
|
// Do not log anything when testing
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user