mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
got optional secondary_database questions working
This commit is contained in:
143
src/install.js
143
src/install.js
@@ -9,6 +9,8 @@ var async = require('async'),
|
||||
nconf = require('nconf'),
|
||||
utils = require('../public/src/utils.js'),
|
||||
|
||||
ALLOWED_DATABASES = ['redis', 'mongo', 'level'],
|
||||
|
||||
install = {
|
||||
questions: [{
|
||||
name: 'base_url',
|
||||
@@ -40,6 +42,10 @@ 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',
|
||||
@@ -134,18 +140,22 @@ var async = require('async'),
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
var success = function (err, config) {
|
||||
var success = function (err, config, callback) {
|
||||
if (!config) {
|
||||
return next(new Error('aborted'));
|
||||
}
|
||||
|
||||
var database = (config.redis || config.mongo || config.level) ? config.secondary_database : config.database;
|
||||
|
||||
winston.info('Now configuring ' + database + ' database:');
|
||||
|
||||
var dbQuestionsSuccess = function (err, databaseConfig) {
|
||||
if (!databaseConfig) {
|
||||
return next(new Error('aborted'));
|
||||
}
|
||||
|
||||
// Translate redis properties into redis object
|
||||
if(config.database === 'redis') {
|
||||
if(database === 'redis') {
|
||||
config.redis = {
|
||||
host: databaseConfig['redis:host'],
|
||||
port: databaseConfig['redis:port'],
|
||||
@@ -156,7 +166,7 @@ var async = require('async'),
|
||||
if (config.redis.host.slice(0, 1) === '/') {
|
||||
delete config.redis.port;
|
||||
}
|
||||
} else if (config.database === 'mongo') {
|
||||
} else if (database === 'mongo') {
|
||||
config.mongo = {
|
||||
host: databaseConfig['mongo:host'],
|
||||
port: databaseConfig['mongo:port'],
|
||||
@@ -164,19 +174,88 @@ var async = require('async'),
|
||||
password: databaseConfig['mongo:password'],
|
||||
database: databaseConfig['mongo:database']
|
||||
};
|
||||
} else if (config.database === 'level') {
|
||||
} else if (database === 'level') {
|
||||
config.level = {
|
||||
database: databaseConfig['level:database']
|
||||
};
|
||||
} else {
|
||||
return next(new Error('unknown database : ' + config.database));
|
||||
return next(new Error('unknown database : ' + database));
|
||||
}
|
||||
|
||||
var allQuestions = install.redisQuestions.concat(install.mongoQuestions);
|
||||
var allQuestions = install.redisQuestions.concat(install.mongoQuestions.concat(install.levelQuestions));
|
||||
for(var x=0;x<allQuestions.length;x++) {
|
||||
delete config[allQuestions[x].name];
|
||||
}
|
||||
|
||||
callback(err, config);
|
||||
};
|
||||
|
||||
// Add CI object
|
||||
if (install.ciVals) {
|
||||
config['test_database'] = {};
|
||||
for(var prop in install.ciVals) {
|
||||
if (install.ciVals.hasOwnProperty(prop)) {
|
||||
config['test_database'][prop] = install.ciVals[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(database === 'redis') {
|
||||
if (config['redis:host'] && config['redis:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.redisQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'mongo') {
|
||||
if (config['mongo:host'] && config['mongo:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.mongoQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'level') {
|
||||
if (config['level:database']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.levelQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else {
|
||||
return next(new Error('unknown database : ' + database));
|
||||
}
|
||||
};
|
||||
|
||||
// prompt prepends "prompt: " to questions, let's clear that.
|
||||
prompt.start();
|
||||
prompt.message = '';
|
||||
prompt.delimiter = '';
|
||||
|
||||
if (!install.values) {
|
||||
prompt.get(install.questions, function(err, config) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
success(err, config, next);
|
||||
},
|
||||
function(config, next) {
|
||||
if (config.secondary_database && ALLOWED_DATABASES.indexOf(config.secondary_database) !== -1) {
|
||||
success(err, config, next);
|
||||
} else {
|
||||
next(err, config);
|
||||
}
|
||||
}
|
||||
], completeConfigSetup)
|
||||
});
|
||||
} else {
|
||||
// Use provided values, fall back to defaults
|
||||
var config = {},
|
||||
question, x, numQ, allQuestions = install.questions.concat(install.redisQuestions).concat(install.mongoQuestions.concat(install.levelQuestions));
|
||||
for(x=0,numQ=allQuestions.length;x<numQ;x++) {
|
||||
question = allQuestions[x];
|
||||
config[question.name] = install.values[question.name] || question['default'] || '';
|
||||
}
|
||||
|
||||
success(null, config, completeConfigSetup);
|
||||
}
|
||||
|
||||
function completeConfigSetup(err, config) {
|
||||
config.bcrypt_rounds = 12;
|
||||
config.upload_path = '/public/uploads';
|
||||
config.use_port = config.use_port.slice(0, 1) === 'y';
|
||||
@@ -194,59 +273,9 @@ var async = require('async'),
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
require('./database').init(next);
|
||||
});
|
||||
};
|
||||
|
||||
// Add CI object
|
||||
if (install.ciVals) {
|
||||
config['test_database'] = {};
|
||||
for(var prop in install.ciVals) {
|
||||
if (install.ciVals.hasOwnProperty(prop)) {
|
||||
config['test_database'][prop] = install.ciVals[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(config.database === 'redis') {
|
||||
if (config['redis:host'] && config['redis:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.redisQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(config.database === 'mongo') {
|
||||
if (config['mongo:host'] && config['mongo:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.mongoQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(config.database === 'level') {
|
||||
if (config['level:database']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(install.levelQuestions, dbQuestionsSuccess);
|
||||
}
|
||||
} else {
|
||||
return next(new Error('unknown database : ' + config.database));
|
||||
}
|
||||
};
|
||||
|
||||
// prompt prepends "prompt: " to questions, let's clear that.
|
||||
prompt.start();
|
||||
prompt.message = '';
|
||||
prompt.delimiter = '';
|
||||
|
||||
if (!install.values) {
|
||||
prompt.get(install.questions, success);
|
||||
} else {
|
||||
// Use provided values, fall back to defaults
|
||||
var config = {},
|
||||
question, x, numQ, allQuestions = install.questions.concat(install.redisQuestions).concat(install.mongoQuestions.concat(install.levelQuestions));
|
||||
for(x=0,numQ=allQuestions.length;x<numQ;x++) {
|
||||
question = allQuestions[x];
|
||||
config[question.name] = install.values[question.name] || question['default'] || '';
|
||||
}
|
||||
success(null, config);
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
|
||||
Reference in New Issue
Block a user