updated schema handling so that nodebb won't run unless you are up to date -- fixed #498

v1.18.x
Julian Lam 11 years ago
parent 411ba3542c
commit 79c52dfe84

@ -88,8 +88,11 @@
websockets = require('./src/websockets.js'),
posts = require('./src/posts.js'),
plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself
Notifications = require('./src/notifications');
Notifications = require('./src/notifications'),
Upgrade = require('./src/upgrade');
Upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) {
websockets.init(SocketIO);
global.templates = {};
@ -112,6 +115,14 @@
templates.ready(webserver.init);
Notifications.init();
} else {
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
winston.warn(' node app --upgrade');
winston.warn('To ignore this error (not recommended):');
winston.warn(' node app --no-check-schema')
process.exit();
}
});
});
} else if (nconf.get('setup') || !fs.existsSync(__dirname + '/config.json')) {
// New install, ask setup questions

@ -1,16 +1,38 @@
"use strict";
var RDB = require('./redis.js'),
async = require('async'),
winston = require('winston'),
notifications = require('./notifications')
Upgrade = {};
notifications = require('./notifications'),
Upgrade = {},
schemaDate, thisSchemaDate;
Upgrade.check = function(callback) {
var latestSchema = new Date(2013, 10, 11).getTime();
RDB.get('schemaDate', function(err, value) {
if (parseInt(value, 10) > latestSchema) {
callback(true);
} else {
callback(false);
}
});
};
Upgrade.upgrade = function() {
winston.info('Beginning Redis database schema update');
async.series([
function(next) {
RDB.hget('notifications:1', 'score', function(err, score) {
if (score) {
RDB.get('schemaDate', function(err, value) {
schemaDate = value;
next();
});
},
function(next) {
thisSchemaDate = new Date(2013, 9, 3).getTime();
if (schemaDate < thisSchemaDate) {
async.series([
function(next) {
RDB.keys('uid:*:notifications:flag', function(err, keys) {
@ -44,7 +66,10 @@ Upgrade.upgrade = function() {
if (keys.length > 0) {
winston.info('[2013/10/03] Removing Notification Scores');
async.each(keys, function(key, next) {
if (key === 'notifications:next_nid') return next();
if (key === 'notifications:next_nid') {
return next();
}
RDB.hdel(key, 'score', next);
}, next);
} else {
@ -58,11 +83,10 @@ Upgrade.upgrade = function() {
winston.info('[2013/10/03] Updates to Notifications skipped.');
next();
}
});
},
function(next) {
RDB.exists('notifications', function(err, exists) {
if (!exists) {
thisSchemaDate = new Date(2013, 9, 23).getTime();
if (schemaDate < thisSchemaDate) {
RDB.keys('notifications:*', function(err, keys) {
var multi = RDB.multi();
@ -83,11 +107,10 @@ Upgrade.upgrade = function() {
winston.info('[2013/10/23] Updates to Notifications skipped.');
next();
}
});
},
function(next) {
RDB.hget('config', 'postDelay', function(err, postDelay) {
if(parseInt(postDelay, 10) > 150) {
thisSchemaDate = new Date(2013, 10, 11).getTime();
if (schemaDate < thisSchemaDate) {
RDB.hset('config', 'postDelay', 10, function(err, success) {
winston.info('[2013/11/11] Updated postDelay to 10 seconds.');
next();
@ -96,15 +119,21 @@ Upgrade.upgrade = function() {
winston.info('[2013/11/11] Update to postDelay skipped.');
next();
}
});
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!!
], function(err) {
if (!err) {
winston.info('Redis schema update complete!');
RDB.set('schemaDate', thisSchemaDate, function(err) {
if (!err) {
winston.info('[upgrade] Redis schema update complete!');
process.exit();
} else {
winston.error('Errors were encountered while updating the NodeBB schema: ' + err.message);
winston.error('[upgrade] Could not update NodeBB schema date!');
}
});
} else {
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
}
});
};

Loading…
Cancel
Save