Node.js based forum software built for the modern web
#2265 upgrade script
barisusakliffbefda5f7bb
diff --git a/src/upgrade.js b/src/upgrade.jsindex 32781d8ec9..4a46ecaf0f 100644--- a/src/upgrade.js+++ b/src/upgrade.js@@ -19,7 +19,7 @@ var db = require('./database'),schemaDate, thisSchemaDate,// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema- latestSchema = Date.UTC(2014, 9, 3);+ latestSchema = Date.UTC(2014, 9, 14);Upgrade.check = function(callback) {db.get('schemaDate', function(err, value) {@@ -1083,6 +1083,68 @@ Upgrade.upgrade = function(callback) {winston.info('[2014/10/7] Banned users sorted set skipped');next();}+ },+ function(next) {+ function updateCategories(next) {+ db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {+ if (err) {+ return next(err);+ }++ async.eachLimit(cids, 5, function(cid, next) {+ db.sortedSetCard('categories:' + cid + ':tid', function(err, count) {+ if (err) {+ return next(err);+ }+ count = parseInt(count, 10) || 0;+ db.setObjectField('category:' + cid, 'topic_count', count, next);+ });+ }, next);+ });+ }++ function updateTopics(next) {+ db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {+ if (err) {+ return next(err);+ }++ async.eachLimit(tids, 50, function(tid, next) {+ db.sortedSetCard('tid:' + tid + ':posts', function(err, count) {+ if (err) {+ return next(err);+ }+ count = parseInt(count, 10) || 0;+ winston.info('updating tid ' + tid + ' count ' + count);+ db.setObjectField('topic:' + tid, 'postcount', count, next);+ });+ }, next);+ });+ }++ thisSchemaDate = Date.UTC(2014, 9, 14);+ if (schemaDate < thisSchemaDate || 1) {+ winston.info('[2014/10/14] Topic post count migration');++ async.series([+ function(next) {+ updateCategories(next);+ },+ function(next) {+ updateTopics(next);+ }+ ], function(err) {+ if (err) {+ winston.error('[2014/10/14] Error encountered while Topic post count migration');+ return next(err);+ }+ winston.info('[2014/10/14] Topic post count migration done');+ Upgrade.update(thisSchemaDate, next);+ });+ } else {+ winston.info('[2014/10/14] Topic post count migration skipped');+ next();+ }}// Add new schema updates here// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!