diff --git a/core/server/config/defaults.json b/core/server/config/defaults.json index 456828f9a8..5d8d3798e1 100644 --- a/core/server/config/defaults.json +++ b/core/server/config/defaults.json @@ -4,13 +4,6 @@ "host": "127.0.0.1", "port": 2368 }, - "database": { - "client": "sqlite3", - "debug": false, - "connection": { - "filename": "content/data/ghost.db" - } - }, "privacy": false, "paths": { "contentPath": "content/" diff --git a/core/server/config/env/config.development.json b/core/server/config/env/config.development.json index a52ab624fc..6fb291d68a 100644 --- a/core/server/config/env/config.development.json +++ b/core/server/config/env/config.development.json @@ -1,6 +1,7 @@ { "url": "http://localhost:2368", "database": { + "client": "sqlite3", "connection": { "filename": "content/data/ghost-dev.db" }, diff --git a/core/server/config/env/config.production.json b/core/server/config/env/config.production.json index 1d3d647c5d..0d114d2414 100644 --- a/core/server/config/env/config.production.json +++ b/core/server/config/env/config.production.json @@ -1,10 +1,13 @@ { "url": "http://my-ghost-blog.com", "database": { + "client": "mysql", "connection": { - "filename": "content/data/ghost.db" - }, - "debug": false + "host" : "127.0.0.1", + "user" : "root", + "password" : "", + "database" : "ghost" + } }, "paths": { "contentPath": "content/" @@ -14,6 +17,6 @@ "rotation": { "enabled": true }, - "transports": ["file"] + "transports": ["file", "stdout"] } } diff --git a/core/server/config/env/config.testing.json b/core/server/config/env/config.testing.json index 13dc986399..b0ae6e6003 100644 --- a/core/server/config/env/config.testing.json +++ b/core/server/config/env/config.testing.json @@ -1,10 +1,12 @@ { "url": "http://127.0.0.1:2369", "database": { + "client": "sqlite3", "connection": { "filename": "content/data/ghost-test.db" }, - "useNullAsDefault": true + "useNullAsDefault": true, + "debug": false }, "server": { "port": 2369 diff --git a/core/server/config/index.js b/core/server/config/index.js index 34c94e4c36..832f500e7c 100644 --- a/core/server/config/index.js +++ b/core/server/config/index.js @@ -40,7 +40,9 @@ _private.loadNconf = function loadNconf(options) { nconf.makePathsAbsolute = localUtils.makePathsAbsolute.bind(nconf); nconf.isPrivacyDisabled = localUtils.isPrivacyDisabled.bind(nconf); nconf.getContentPath = localUtils.getContentPath.bind(nconf); + nconf.sanitizeDatabaseProperties = localUtils.sanitizeDatabaseProperties.bind(nconf); + nconf.sanitizeDatabaseProperties(); nconf.makePathsAbsolute(nconf.get('paths'), 'paths'); nconf.makePathsAbsolute(nconf.get('database:connection'), 'database:connection'); diff --git a/core/server/config/utils.js b/core/server/config/utils.js index c75036209d..4b7c613d0f 100644 --- a/core/server/config/utils.js +++ b/core/server/config/utils.js @@ -81,3 +81,25 @@ exports.getContentPath = function getContentPath(type) { throw new Error('getContentPath was called with: ' + type); } }; + +/** + * nconf merges all database keys together and this can be confusing + * e.g. production default database is sqlite, but you override the configuration with mysql + * + * this.clear('key') does not work + * https://github.com/indexzero/nconf/issues/235#issuecomment-257606507 + */ +exports.sanitizeDatabaseProperties = function sanitizeDatabaseProperties() { + var database = this.get('database'); + + if (this.get('database:client') === 'mysql') { + delete database.connection.filename; + } else { + delete database.connection.host; + delete database.connection.user; + delete database.connection.password; + delete database.connection.database; + } + + this.set('database', database); +};