diff --git a/src/database.js b/src/database.js index 71775e8807..66f503370f 100644 --- a/src/database.js +++ b/src/database.js @@ -1,14 +1,35 @@ - +"use strict"; var nconf = require('nconf'), - databaseType = nconf.get('database'), - winston = require('winston'); + primaryDBConfig = nconf.get('database'), + secondaryDBConfig = nconf.get('secondary_database'), + secondaryModules = nconf.get('secondary_db_modules'), + winston = require('winston'), + + ALLOWED_MODULES = ['hash', 'list', 'sets', 'sorted']; -if(!databaseType) { +if(!primaryDBConfig) { winston.info('Database type not set! Run node app --setup'); process.exit(); } -var db = require('./database/' + databaseType); +function setupSecondaryDB() { + var secondaryDB = require('./database/' + secondaryDBConfig); + + secondaryModules = secondaryModules.split(/,\s*/); + + for (var module in secondaryModules) { + if (secondaryModules.hasOwnProperty(module) && ALLOWED_MODULES.indexOf(module) !== -1) { + primaryDB[module] = secondaryDB[module]; + } + } +} + + +var primaryDB = require('./database/' + primaryDBConfig); + +if (secondaryDBConfig && secondaryModules) { + setupSecondaryDB(); +} -module.exports = db; \ No newline at end of file +module.exports = primaryDB; \ No newline at end of file diff --git a/src/install.js b/src/install.js index e7c99691ec..1b58a45a87 100644 --- a/src/install.js +++ b/src/install.js @@ -42,10 +42,6 @@ var async = require('async'), name: 'database', description: 'Which database to use', 'default': nconf.get('database') || 'redis' - }, { - name: 'secondary_database', - description: 'Use secondary database? (optional)', - 'default': nconf.get('secondary_database') || 'none' }], redisQuestions : [{ name: 'redis:host', @@ -244,20 +240,18 @@ var async = require('async'), if (!install.values) { prompt.get(install.questions, function(err, config) { - async.waterfall([ - function(next) { - winston.info('Now configuring ' + config.database + ' database:'); - success(err, config, next); - }, - function(config, next) { - winston.info('Now configuring ' + config.secondary_database + ' database:'); - if (config.secondary_database && ALLOWED_DATABASES.indexOf(config.secondary_database) !== -1) { - getSecondaryDatabaseModules(config, next); - } else { - next(err, config); - } - } - ], completeConfigSetup); + if (nconf.get('advanced')) { + prompt.get({ + name: 'secondary_database', + description: 'Select secondary database', + 'default': nconf.get('secondary_database') || 'none' + }, function(err, dbConfig) { + config.secondary_database = dbConfig.secondary_database; + configureDatabases(err, config); + }); + } else { + configureDatabases(err, config); + } }); } else { // Use provided values, fall back to defaults @@ -282,6 +276,23 @@ var async = require('async'), }); } + function configureDatabases(err, config) { + async.waterfall([ + function(next) { + winston.info('Now configuring ' + config.database + ' database:'); + success(err, config, next); + }, + function(config, next) { + winston.info('Now configuring ' + config.secondary_database + ' database:'); + if (config.secondary_database && ALLOWED_DATABASES.indexOf(config.secondary_database) !== -1) { + getSecondaryDatabaseModules(config, next); + } else { + next(err, config); + } + } + ], completeConfigSetup); + } + function completeConfigSetup(err, config) { config.bcrypt_rounds = 12; config.upload_path = '/public/uploads';