Skip to content

Commit

Permalink
馃帹 updates for database configuration (#7975)
Browse files Browse the repository at this point in the history
* 馃帹  update configuration files: database

refs #7488

- no default database configuration
- production: default is MySQL

* 馃帹  add transport stdout to production for now

refs #7488

- production will log to stdout and file for now
- to reduce the risk of confusing users
- users would not see any stdout and they don't know that Ghost logs into file only in production

* 馃帹  sanitize database properties

refs #7488
  • Loading branch information
kirrg001 authored and ErisDS committed Feb 11, 2017
1 parent 53bd7da commit d9e87aa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
7 changes: 0 additions & 7 deletions core/server/config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
1 change: 1 addition & 0 deletions core/server/config/env/config.development.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"url": "http://localhost:2368",
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/ghost-dev.db"
},
Expand Down
11 changes: 7 additions & 4 deletions core/server/config/env/config.production.json
Original file line number Diff line number Diff line change
@@ -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/"
Expand All @@ -14,6 +17,6 @@
"rotation": {
"enabled": true
},
"transports": ["file"]
"transports": ["file", "stdout"]
}
}
4 changes: 3 additions & 1 deletion core/server/config/env/config.testing.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions core/server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
22 changes: 22 additions & 0 deletions core/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit d9e87aa

Please sign in to comment.