From 5c57ed5ea0469df3e630637f7e83794a6680aa67 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 23 Jul 2014 13:30:12 -0400 Subject: [PATCH] install db dependencies in upgrade script --- src/install.js | 20 ++++++++++++-------- src/upgrade.js | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/install.js b/src/install.js index 2fe604029b..476ce87a9c 100644 --- a/src/install.js +++ b/src/install.js @@ -206,6 +206,16 @@ function completeConfigSetup(err, config, next) { } function setupDatabase(server_conf, next) { + install.installDbDependencies(server_conf, function(err) { + if (err) { + return next(err); + } + + require('./database').init(next); + }); +} + +install.installDbDependencies = function(server_conf, next) { var npm = require('npm'), packages = []; @@ -221,15 +231,9 @@ function setupDatabase(server_conf, next) { packages = packages.concat(DATABASES[server_conf.secondary_database].dependencies); } - npm.commands.install(packages, function(err) { - if (err) { - return next(err); - } - - require('./database').init(next); - }); + npm.commands.install(packages, next); }); -} +}; function setupDefaultConfigs(next) { winston.info('Populating database with default configs, if not already set...'); diff --git a/src/upgrade.js b/src/upgrade.js index 740a9ed4ee..0f908b1079 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, 5, 17); + latestSchema = Date.UTC(2014, 6, 23); Upgrade.check = function(callback) { db.get('schemaDate', function(err, value) { @@ -861,6 +861,26 @@ Upgrade.upgrade = function(callback) { winston.info('[2014/6/17] Category post count upgrade - skipped'); next(); } + }, + function(next) { + thisSchemaDate = Date.UTC(2014, 6, 23); + + if (schemaDate < thisSchemaDate) { + winston.info('[2014/7/23] Upgrading db dependencies...'); + var install = require('./install'); + var config = require('../config.json'); + install.installDbDependencies(config, function(err) { + if (err) { + winston.error('[2014/7/23] Error encountered while upgrading db dependencies'); + return next(err); + } + winston.error('[2014/7/23] Upgraded db dependencies'); + Upgrade.update(thisSchemaDate, next); + }); + } else { + winston.info('[2014/7/23] Upgrading db dependencies - skipped'); + next(); + } } // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!