mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +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'),
|
nconf = require('nconf'),
|
||||||
utils = require('../public/src/utils.js'),
|
utils = require('../public/src/utils.js'),
|
||||||
|
|
||||||
|
ALLOWED_DATABASES = ['redis', 'mongo', 'level'],
|
||||||
|
|
||||||
install = {
|
install = {
|
||||||
questions: [{
|
questions: [{
|
||||||
name: 'base_url',
|
name: 'base_url',
|
||||||
@@ -40,6 +42,10 @@ var async = require('async'),
|
|||||||
name: 'database',
|
name: 'database',
|
||||||
description: 'Which database to use',
|
description: 'Which database to use',
|
||||||
'default': nconf.get('database') || 'redis'
|
'default': nconf.get('database') || 'redis'
|
||||||
|
}, {
|
||||||
|
name: 'secondary_database',
|
||||||
|
description: 'Use secondary database? (optional)',
|
||||||
|
'default': nconf.get('secondary_database') || 'none'
|
||||||
}],
|
}],
|
||||||
redisQuestions : [{
|
redisQuestions : [{
|
||||||
name: 'redis:host',
|
name: 'redis:host',
|
||||||
@@ -134,18 +140,22 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
var success = function (err, config) {
|
var success = function (err, config, callback) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return next(new Error('aborted'));
|
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) {
|
var dbQuestionsSuccess = function (err, databaseConfig) {
|
||||||
if (!databaseConfig) {
|
if (!databaseConfig) {
|
||||||
return next(new Error('aborted'));
|
return next(new Error('aborted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate redis properties into redis object
|
// Translate redis properties into redis object
|
||||||
if(config.database === 'redis') {
|
if(database === 'redis') {
|
||||||
config.redis = {
|
config.redis = {
|
||||||
host: databaseConfig['redis:host'],
|
host: databaseConfig['redis:host'],
|
||||||
port: databaseConfig['redis:port'],
|
port: databaseConfig['redis:port'],
|
||||||
@@ -156,7 +166,7 @@ var async = require('async'),
|
|||||||
if (config.redis.host.slice(0, 1) === '/') {
|
if (config.redis.host.slice(0, 1) === '/') {
|
||||||
delete config.redis.port;
|
delete config.redis.port;
|
||||||
}
|
}
|
||||||
} else if (config.database === 'mongo') {
|
} else if (database === 'mongo') {
|
||||||
config.mongo = {
|
config.mongo = {
|
||||||
host: databaseConfig['mongo:host'],
|
host: databaseConfig['mongo:host'],
|
||||||
port: databaseConfig['mongo:port'],
|
port: databaseConfig['mongo:port'],
|
||||||
@@ -164,19 +174,88 @@ var async = require('async'),
|
|||||||
password: databaseConfig['mongo:password'],
|
password: databaseConfig['mongo:password'],
|
||||||
database: databaseConfig['mongo:database']
|
database: databaseConfig['mongo:database']
|
||||||
};
|
};
|
||||||
} else if (config.database === 'level') {
|
} else if (database === 'level') {
|
||||||
config.level = {
|
config.level = {
|
||||||
database: databaseConfig['level:database']
|
database: databaseConfig['level:database']
|
||||||
};
|
};
|
||||||
} else {
|
} 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++) {
|
for(var x=0;x<allQuestions.length;x++) {
|
||||||
delete config[allQuestions[x].name];
|
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.bcrypt_rounds = 12;
|
||||||
config.upload_path = '/public/uploads';
|
config.upload_path = '/public/uploads';
|
||||||
config.use_port = config.use_port.slice(0, 1) === 'y';
|
config.use_port = config.use_port.slice(0, 1) === 'y';
|
||||||
@@ -194,59 +273,9 @@ var async = require('async'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
require('./database').init(next);
|
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) {
|
function (next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user