mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
moved database specific questions into install/databases.js
This commit is contained in:
112
install/databases.js
Normal file
112
install/databases.js
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
|
||||
var async = require('async'),
|
||||
prompt = require('prompt'),
|
||||
nconf = require('nconf'),
|
||||
winston = require('winston'),
|
||||
|
||||
questions = {};
|
||||
|
||||
// maybe this should go into install/database.js
|
||||
function success(err, config, callback) {
|
||||
if (!config) {
|
||||
return callback(new Error('aborted'));
|
||||
}
|
||||
|
||||
var database = (config.redis || config.mongo || config.level) ? config.secondary_database : config.database;
|
||||
|
||||
function dbQuestionsSuccess(err, databaseConfig) {
|
||||
if (!databaseConfig) {
|
||||
return callback(new Error('aborted'));
|
||||
}
|
||||
|
||||
// Translate redis properties into redis object
|
||||
if(database === 'redis') {
|
||||
config.redis = {
|
||||
host: databaseConfig['redis:host'],
|
||||
port: databaseConfig['redis:port'],
|
||||
password: databaseConfig['redis:password'],
|
||||
database: databaseConfig['redis:database']
|
||||
};
|
||||
|
||||
if (config.redis.host.slice(0, 1) === '/') {
|
||||
delete config.redis.port;
|
||||
}
|
||||
} else if (database === 'mongo') {
|
||||
config.mongo = {
|
||||
host: databaseConfig['mongo:host'],
|
||||
port: databaseConfig['mongo:port'],
|
||||
username: databaseConfig['mongo:username'],
|
||||
password: databaseConfig['mongo:password'],
|
||||
database: databaseConfig['mongo:database']
|
||||
};
|
||||
} else if (database === 'level') {
|
||||
config.level = {
|
||||
database: databaseConfig['level:database']
|
||||
};
|
||||
} else {
|
||||
return callback(new Error('unknown database : ' + database));
|
||||
}
|
||||
|
||||
var allQuestions = questions.redis.concat(questions.mongo.concat(questions.level));
|
||||
for(var x=0;x<allQuestions.length;x++) {
|
||||
delete config[allQuestions[x].name];
|
||||
}
|
||||
|
||||
callback(err, config);
|
||||
}
|
||||
|
||||
if(database === 'redis') {
|
||||
if (config['redis:host'] && config['redis:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.redis, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'mongo') {
|
||||
if (config['mongo:host'] && config['mongo:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.mongo, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'level') {
|
||||
if (config['level:database']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.level, dbQuestionsSuccess);
|
||||
}
|
||||
} else {
|
||||
return callback(new Error('unknown database : ' + database));
|
||||
}
|
||||
}
|
||||
|
||||
function getSecondaryDatabaseModules(config, next) {
|
||||
prompt.get({
|
||||
"name": "secondary_db_modules",
|
||||
"description": "Which database modules should " + config.secondary_database + " store?",
|
||||
"default": nconf.get('secondary_db_modules') || "hash, list, sets, sorted"
|
||||
}, function(err, db) {
|
||||
config.secondary_db_modules = db.secondary_db_modules;
|
||||
success(err, config, next);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function(err, config, allowedDBs, callback) {
|
||||
allowedDBs.forEach(function(db) {
|
||||
questions[db] = require('./../src/database/' + db).questions;
|
||||
});
|
||||
|
||||
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 && allowedDBs.indexOf(config.secondary_database) !== -1) {
|
||||
getSecondaryDatabaseModules(config, next);
|
||||
} else {
|
||||
next(err, config);
|
||||
}
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
167
src/install.js
167
src/install.js
@@ -56,10 +56,6 @@ questions.main = [
|
||||
|
||||
|
||||
|
||||
ALLOWED_DATABASES.forEach(function(db) {
|
||||
questions[db] = require('./database/' + db).questions;
|
||||
});
|
||||
|
||||
function checkSetupFlag(next) {
|
||||
var setupVal;
|
||||
try {
|
||||
@@ -127,55 +123,49 @@ function checkCIFlag(next) {
|
||||
|
||||
|
||||
function setupConfig(next) {
|
||||
// maybe this should go into install/database.js
|
||||
function success(err, config, callback) {
|
||||
if (!config) {
|
||||
return next(new Error('aborted'));
|
||||
}
|
||||
var configureDatabases = require('./../install/databases');
|
||||
|
||||
var database = (config.redis || config.mongo || config.level) ? config.secondary_database : config.database;
|
||||
// prompt prepends "prompt: " to questions, let's clear that.
|
||||
prompt.start();
|
||||
prompt.message = '';
|
||||
prompt.delimiter = '';
|
||||
|
||||
function dbQuestionsSuccess(err, databaseConfig) {
|
||||
if (!databaseConfig) {
|
||||
return next(new Error('aborted'));
|
||||
}
|
||||
|
||||
// Translate redis properties into redis object
|
||||
if(database === 'redis') {
|
||||
config.redis = {
|
||||
host: databaseConfig['redis:host'],
|
||||
port: databaseConfig['redis:port'],
|
||||
password: databaseConfig['redis:password'],
|
||||
database: databaseConfig['redis:database']
|
||||
};
|
||||
|
||||
if (config.redis.host.slice(0, 1) === '/') {
|
||||
delete config.redis.port;
|
||||
}
|
||||
} else if (database === 'mongo') {
|
||||
config.mongo = {
|
||||
host: databaseConfig['mongo:host'],
|
||||
port: databaseConfig['mongo:port'],
|
||||
username: databaseConfig['mongo:username'],
|
||||
password: databaseConfig['mongo:password'],
|
||||
database: databaseConfig['mongo:database']
|
||||
};
|
||||
} else if (database === 'level') {
|
||||
config.level = {
|
||||
database: databaseConfig['level:database']
|
||||
};
|
||||
if (!install.values) {
|
||||
prompt.get(questions.main, function(err, config) {
|
||||
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, ALLOWED_DATABASES, function(err, config) {
|
||||
completeConfigSetup(err, config, next);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return next(new Error('unknown database : ' + database));
|
||||
configureDatabases(err, config, ALLOWED_DATABASES, function(err, config) {
|
||||
completeConfigSetup(err, config, next);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Use provided values, fall back to defaults
|
||||
var config = {},
|
||||
question, x, numQ, allQuestions = questions.main.concat(questions.redis).concat(questions.mongo.concat(questions.level));
|
||||
|
||||
for(x=0,numQ=allQuestions.length;x<numQ;x++) {
|
||||
question = allQuestions[x];
|
||||
config[question.name] = install.values[question.name] || question['default'] || '';
|
||||
}
|
||||
|
||||
var allQuestions = questions.redis.concat(questions.mongo.concat(questions.level));
|
||||
for(var x=0;x<allQuestions.length;x++) {
|
||||
delete config[allQuestions[x].name];
|
||||
}
|
||||
|
||||
callback(err, config);
|
||||
configureDatabases(null, config, ALLOWED_DATABASES, function(err, config) {
|
||||
completeConfigSetup(err, config, next);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function completeConfigSetup(err, config, next) {
|
||||
// Add CI object
|
||||
if (install.ciVals) {
|
||||
config.test_database = {};
|
||||
@@ -186,58 +176,6 @@ function setupConfig(next) {
|
||||
}
|
||||
}
|
||||
|
||||
if(database === 'redis') {
|
||||
if (config['redis:host'] && config['redis:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.redis, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'mongo') {
|
||||
if (config['mongo:host'] && config['mongo:port']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.mongo, dbQuestionsSuccess);
|
||||
}
|
||||
} else if(database === 'level') {
|
||||
if (config['level:database']) {
|
||||
dbQuestionsSuccess(null, config);
|
||||
} else {
|
||||
prompt.get(questions.level, dbQuestionsSuccess);
|
||||
}
|
||||
} else {
|
||||
return next(new Error('unknown database : ' + database));
|
||||
}
|
||||
}
|
||||
|
||||
function getSecondaryDatabaseModules(config, next) {
|
||||
prompt.get({
|
||||
"name": "secondary_db_modules",
|
||||
"description": "Which database modules should " + config.secondary_database + " store?",
|
||||
"default": nconf.get('secondary_db_modules') || "hash, list, sets, sorted"
|
||||
}, function(err, db) {
|
||||
config.secondary_db_modules = db.secondary_db_modules;
|
||||
success(err, config, next);
|
||||
});
|
||||
}
|
||||
|
||||
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';
|
||||
config.use_port = config.use_port.slice(0, 1) === 'y';
|
||||
@@ -258,39 +196,6 @@ function setupConfig(next) {
|
||||
|
||||
require('./database').init(next);
|
||||
});
|
||||
}
|
||||
|
||||
// prompt prepends "prompt: " to questions, let's clear that.
|
||||
prompt.start();
|
||||
prompt.message = '';
|
||||
prompt.delimiter = '';
|
||||
|
||||
if (!install.values) {
|
||||
prompt.get(questions.main, function(err, config) {
|
||||
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
|
||||
var config = {},
|
||||
question, x, numQ, allQuestions = questions.main.concat(questions.redis).concat(questions.mongo.concat(questions.level));
|
||||
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 setupDefaultConfigs(next) {
|
||||
|
||||
Reference in New Issue
Block a user