Node.js based forum software built for the modern web
Merge branch 'develop' into upgrades-refactor
Julian Lam513f72c0e943
diff --cc src/upgrade.jsindex 847197357d,e11069b906..80aa38206f--- a/src/upgrade.js+++ b/src/upgrade.js@@@ -1,68 -1,21 +1,68 @@@-'use strict';+/* jslint node: true */+'use strict';-var db = require('./database');var async = require('async');-var winston = require('winston');--var Upgrade = {};+var path = require('path');-var minSchemaDate = Date.UTC(2016, 8, 7); // This value gets updated every new MAJOR version-var schemaDate;-var thisSchemaDate;--// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema-var latestSchema = Date.UTC(2017, 1, 27);+var db = require('./database');+var utils = require('../public/src/utils');++/*+ * Need to write an upgrade script for NodeBB? Cool.+ *+ * 1. Copy TEMPLATE to a file name of your choice. Try to be succinct.+ * 2. Open up that file and change the user-friendly name (can be longer/more descriptive than the file name)+ * and timestamp+ * 3. Add your script under the "method" property+ * 4. Append your filename to the array below for the next NodeBB version.+ */++var Upgrade = {+ available: [+ {+ version: '1.0.0',+ upgrades: ['chat_upgrade', 'chat_room_hashes', 'theme_to_active_plugins', 'user_best_posts', 'users_notvalidated', 'global_moderators', 'social_post_sharing'],+ },+ {+ version: '1.1.0',+ upgrades: ['group_title_update', 'user_post_count_per_tid', 'dismiss_flags_from_deleted_topics', 'assign_topic_read_privilege', 'separate_upvote_downvote'],+ },+ {+ version: '1.1.1',+ upgrades: ['upload_privileges', 'remove_negative_best_posts'],+ },+ {+ version: '1.2.0',+ upgrades: ['category_recent_tids', 'edit_delete_deletetopic_privileges'],+ },+ {+ version: '1.3.0',+ upgrades: ['favourites_to_bookmarks', 'sorted_sets_for_post_replies'],+ },+ {+ version: '1.4.0',+ upgrades: ['global_and_user_language_keys', 'sorted_set_for_pinned_topics'],+ },+ {+ version: 'master', // rename this to whenever the next NodeBB version is (non-breaking)- upgrades: ['sound_settings'],++ upgrades: ['sound_settings', 'post_votes_zset'],+ },+ {+ version: 'develop', // rename this to whatever the next NodeBB version is (breaking)+ upgrades: ['flags_refactor'],+ },+ ],+};Upgrade.check = function (callback) {- db.get('schemaDate', function (err, value) {+ // Throw 'schema-out-of-date' if not all upgrade scripts have run+ var all = Upgrade.available.reduce(function (memo, current) {+ memo = memo.concat(current.upgrades);+ return memo;+ }, []);++ db.getSortedSetRange('schemaLog', 0, -1, function (err, executed) {if (err) {return callback(err);}diff --cc src/upgrades/post_votes_zset.jsindex 0000000000,0000000000..c1eefb6688new file mode 100644--- /dev/null+++ b/src/upgrades/post_votes_zset.js@@@ -1,0 -1,0 +1,26 @@@++/* jslint node: true */++++'use strict';++++var db = require('../database');++++var async = require('async');++++module.exports = {++ name: 'New sorted set posts:votes',++ timestamp: Date.UTC(2017, 1, 27),++ method: function (callback) {++ require('../batch').processSortedSet('posts:pid', function (pids, next) {++ async.each(pids, function (pid, next) {++ db.getObjectFields('post:' + pid, ['upvotes', 'downvotes'], function (err, postData) {++ if (err || !postData) {++ return next(err);++ }++++ var votes = parseInt(postData.upvotes || 0, 10) - parseInt(postData.downvotes || 0, 10);++ db.sortedSetAdd('posts:votes', votes, pid, next);++ });++ }, next);++ }, {}, callback);++ },++};