From 64aa89f5eee9cd1bef57ea91a5f7bd01885a717f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 5 Mar 2014 19:33:10 -0500 Subject: [PATCH 1/3] updating upgrade script to use UTC timestamps *facepalm*. God, I hope I didn't break anything... (first pass #1155) --- src/upgrade.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index 0876aa7113..08b5594ab1 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -15,11 +15,11 @@ var db = require('./database'), Upgrade = {}, - minSchemaDate = new Date(2014, 0, 4).getTime(), // This value gets updated every new MINOR version + minSchemaDate = Date.UTC(2014, 0, 4), // This value gets updated every new MINOR version schemaDate, thisSchemaDate, // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - latestSchema = new Date(2014, 1, 22).getTime(); + latestSchema = Date.UTC(2014, 1, 22); Upgrade.check = function(callback) { db.get('schemaDate', function(err, value) { @@ -64,7 +64,7 @@ Upgrade.upgrade = function(callback) { }); }, function(next) { - thisSchemaDate = new Date(2014, 0, 5).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 5); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -108,7 +108,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 5, 14, 6).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 5, 14, 6); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -257,7 +257,7 @@ Upgrade.upgrade = function(callback) { }); } - thisSchemaDate = new Date(2014, 0, 7).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 7); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -277,7 +277,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 13, 12, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 13, 12, 0); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -300,7 +300,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 19, 22, 19).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 19, 22, 19); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -318,7 +318,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 23, 16, 5).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 23, 16, 5); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -342,7 +342,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 25, 0, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 25, 0, 0); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -377,7 +377,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 27, 12, 35).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 27, 12, 35); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -421,7 +421,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 30, 15, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 30, 15, 0); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -446,7 +446,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 0, 30, 16, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 0, 30, 16, 0); function updateTopic(tid, next) { Topics.getTopicFields(tid, ['postcount', 'viewcount'], function(err, topicData) { @@ -494,7 +494,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 2, 16, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 2, 16, 0); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -532,7 +532,7 @@ Upgrade.upgrade = function(callback) { }, function(next) { - thisSchemaDate = new Date(2014, 1, 7, 16, 0).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 7, 16, 0); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -577,7 +577,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 9, 20, 50).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 9, 20, 50); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -596,7 +596,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 14, 20, 50).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 14, 20, 50); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -646,7 +646,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 14, 21, 50).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 14, 21, 50); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -702,7 +702,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 19, 18, 15).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 19, 18, 15); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -728,7 +728,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 20, 15, 30).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 20, 15, 30); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -767,7 +767,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 20, 16, 15).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 20, 16, 15); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -787,7 +787,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 20, 19, 45).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 20, 19, 45); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -813,7 +813,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 20, 20, 25).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 20, 20, 25); if (schemaDate < thisSchemaDate) { updatesMade = true; @@ -830,7 +830,7 @@ Upgrade.upgrade = function(callback) { } }, function(next) { - thisSchemaDate = new Date(2014, 1, 22).getTime(); + thisSchemaDate = Date.UTC(2014, 1, 22); if (schemaDate < thisSchemaDate) { updatesMade = true; From 5f52ef5f01c7003088c645acdc6d6cebf9365dd5 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 5 Mar 2014 19:41:16 -0500 Subject: [PATCH 2/3] removed all 0.3.x related upgrade scripts, and updated minSchemaDate --- src/upgrade.js | 640 +------------------------------------------------ 1 file changed, 1 insertion(+), 639 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index 08b5594ab1..51f75232d8 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -15,7 +15,7 @@ var db = require('./database'), Upgrade = {}, - minSchemaDate = Date.UTC(2014, 0, 4), // This value gets updated every new MINOR version + minSchemaDate = Date.UTC(2014, 1, 14, 21, 50), // This value gets updated every new MINOR version schemaDate, thisSchemaDate, // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema @@ -63,644 +63,6 @@ Upgrade.upgrade = function(callback) { } }); }, - function(next) { - thisSchemaDate = Date.UTC(2014, 0, 5); - if (schemaDate < thisSchemaDate) { - updatesMade = true; - - db.getListRange('categories:cid', 0, -1, function(err, cids) { - if(err) { - return next(err); - } - - var timestamp = Date.now(); - - function upgradeCategory(cid, next) { - db.getSetMembers('cid:' + cid + ':active_users', function(err, uids) { - if(err) { - return next(err); - } - - db.delete('cid:' + cid + ':active_users', function(err) { - if(err) { - return next(err); - } - - for(var i=0; i Date: Wed, 5 Mar 2014 19:51:16 -0500 Subject: [PATCH 3/3] final pass, resolved #1155 --- src/upgrade.js | 54 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index 51f75232d8..9221d29cd0 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -38,6 +38,10 @@ Upgrade.check = function(callback) { }); }; +Upgrade.update = function(schemaDate, callback) { + db.set('schemaDate', schemaDate, callback); +}; + Upgrade.upgrade = function(callback) { var updatesMade = false; @@ -67,8 +71,6 @@ Upgrade.upgrade = function(callback) { thisSchemaDate = Date.UTC(2014, 1, 19, 18, 15); if (schemaDate < thisSchemaDate) { - updatesMade = true; - db.setObjectField('widgets:home.tpl', 'motd', JSON.stringify([ { "widget": "html", @@ -82,7 +84,12 @@ Upgrade.upgrade = function(callback) { Meta.configs.remove('show_motd'); winston.info('[2014/2/19] Updated MOTD to use the HTML widget.'); - next(err); + + if (err) { + next(err); + } else { + Upgrade.update(thisSchemaDate, next); + } }); } else { winston.info('[2014/2/19] Updating MOTD to use the HTML widget - skipped'); @@ -93,8 +100,6 @@ Upgrade.upgrade = function(callback) { thisSchemaDate = Date.UTC(2014, 1, 20, 15, 30); if (schemaDate < thisSchemaDate) { - updatesMade = true; - var container = '
{title}
{body}
'; db.setObjectField('widgets:category.tpl', 'sidebar', JSON.stringify([ @@ -121,7 +126,12 @@ Upgrade.upgrade = function(callback) { } ]), function(err) { winston.info('[2014/2/20] Adding Recent Replies, Active Users, and Moderator widgets to category sidebar.'); - next(err); + + if (err) { + next(err); + } else { + Upgrade.update(thisSchemaDate, next); + } }); } else { winston.info('[2014/2/20] Adding Recent Replies, Active Users, and Moderator widgets to category sidebar - skipped'); @@ -132,8 +142,6 @@ Upgrade.upgrade = function(callback) { thisSchemaDate = Date.UTC(2014, 1, 20, 16, 15); if (schemaDate < thisSchemaDate) { - updatesMade = true; - db.setObjectField('widgets:home.tpl', 'footer', JSON.stringify([ { "widget": "forumstats", @@ -141,7 +149,12 @@ Upgrade.upgrade = function(callback) { } ]), function(err) { winston.info('[2014/2/20] Adding Forum Stats Widget to the Homepage Footer.'); - next(err); + + if (err) { + next(err); + } else { + Upgrade.update(thisSchemaDate, next); + } }); } else { winston.info('[2014/2/20] Adding Forum Stats Widget to the Homepage Footer - skipped'); @@ -152,8 +165,6 @@ Upgrade.upgrade = function(callback) { thisSchemaDate = Date.UTC(2014, 1, 20, 19, 45); if (schemaDate < thisSchemaDate) { - updatesMade = true; - var container = '
{title}
{body}
'; db.setObjectField('widgets:home.tpl', 'sidebar', JSON.stringify([ @@ -167,7 +178,12 @@ Upgrade.upgrade = function(callback) { } ]), function(err) { winston.info('[2014/2/20] Updating Lavender MOTD'); - next(err); + + if (err) { + next(err); + } else { + Upgrade.update(thisSchemaDate, next); + } }); } else { winston.info('[2014/2/20] Updating Lavender MOTD - skipped'); @@ -178,8 +194,6 @@ Upgrade.upgrade = function(callback) { thisSchemaDate = Date.UTC(2014, 1, 20, 20, 25); if (schemaDate < thisSchemaDate) { - updatesMade = true; - db.setAdd('plugins:active', 'nodebb-widget-essentials', function(err) { winston.info('[2014/2/20] Activating NodeBB Essential Widgets'); Plugins.reload(function() { @@ -188,15 +202,18 @@ Upgrade.upgrade = function(callback) { }); } else { winston.info('[2014/2/20] Activating NodeBB Essential Widgets - skipped'); - next(); + + if (err) { + next(err); + } else { + Upgrade.update(thisSchemaDate, next); + } } }, function(next) { thisSchemaDate = Date.UTC(2014, 1, 22); if (schemaDate < thisSchemaDate) { - updatesMade = true; - db.exists('categories:cid', function(err, exists) { if(err) { return next(err); @@ -239,7 +256,8 @@ Upgrade.upgrade = function(callback) { return next(err); } winston.info('[2014/2/22] Added categories to sorted set'); - db.delete('categories:cid:old', next); + db.delete('categories:cid:old'); + Upgrade.update(thisSchemaDate, next); }); }); });