From d75cc60e7644a755f784126b77d7b7befc2139d3 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 26 Feb 2017 15:53:25 -0500 Subject: [PATCH] added upgrade.check back into upgrade.js --- src/start.js | 12 ++++++------ src/upgrade.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/start.js b/src/start.js index 87c0d2bf70..731e939911 100644 --- a/src/start.js +++ b/src/start.js @@ -58,16 +58,16 @@ start.start = function () { if (err) { switch (err.message) { case 'schema-out-of-date': - winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); - winston.warn(' ./nodebb upgrade'); + winston.error('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); + winston.error(' ./nodebb upgrade'); break; case 'dependencies-out-of-date': - winston.warn('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:'); - winston.warn(' ./nodebb upgrade'); + winston.error('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:'); + winston.error(' ./nodebb upgrade'); break; case 'dependencies-missing': - winston.warn('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:'); - winston.warn(' ./nodebb upgrade'); + winston.error('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:'); + winston.error(' ./nodebb upgrade'); break; default: winston.error(err); diff --git a/src/upgrade.js b/src/upgrade.js index 06b4ec50ed..0f7e55c438 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -51,6 +51,22 @@ var Upgrade = { ], }; +Upgrade.check = function (callback) { + // 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) { + var remainder = all.filter(function (name) { + return executed.indexOf(name) === -1; + }); + + callback(remainder.length > 1 ? new Error('schema-out-of-date') : null); + }); +}; + Upgrade.run = function (callback) { process.stdout.write('\nParsing upgrade scripts... '); var queue = [];