mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
a36191de5c
closes #9587 - when `useNullAsDefault` was invented in knex 0.10, it was a breaking change, that update/insert etc no longer set's null as default if a field is missing - at this time we thought it only affects our test env, because the test generator doesn't generate all fields - but turned out the importer is affected as well e.g. you import a post with missing fields - the importer doesn't iterate over all fields and checks if the field is present or not - as this only happens with SQlite3, we should enable `useNullAsDefault` by default - you can still disable this option if you want, but not recommended - the reason why knex added this breaking change was that some applications want "undefined" as value - this is not the case in Ghost, so it's fine to make use of the default null behaviour
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
var knex = require('knex'),
|
|
config = require('../../config'),
|
|
common = require('../../lib/common'),
|
|
knexInstance;
|
|
|
|
// @TODO:
|
|
// - if you require this file before config file was loaded,
|
|
// - then this file is cached and you have no chance to connect to the db anymore
|
|
// - bring dynamic into this file (db.connect())
|
|
function configure(dbConfig) {
|
|
var client = dbConfig.client;
|
|
|
|
if (client === 'sqlite3') {
|
|
dbConfig.useNullAsDefault = dbConfig.hasOwnProperty('useNullAsDefault') ? dbConfig.useNullAsDefault : true;
|
|
}
|
|
|
|
if (client === 'mysql') {
|
|
dbConfig.connection.timezone = 'UTC';
|
|
dbConfig.connection.charset = 'utf8mb4';
|
|
|
|
dbConfig.connection.loggingHook = function loggingHook(err) {
|
|
common.logging.error(new common.errors.InternalServerError({
|
|
code: 'MYSQL_LOGGING_HOOK',
|
|
err: err
|
|
}));
|
|
};
|
|
}
|
|
|
|
return dbConfig;
|
|
}
|
|
|
|
if (!knexInstance && config.get('database') && config.get('database').client) {
|
|
knexInstance = knex(configure(config.get('database')));
|
|
}
|
|
|
|
module.exports = knexInstance;
|