Skip to content

Commit

Permalink
🎨 🔦 do not append isPostgreSQL to config
Browse files Browse the repository at this point in the history
refs #6982
- we cannot add functions to nconf

[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent 0ae0a0b commit 34e48dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions core/server/data/db/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ var knex = require('knex'),
config = require('../../config'),
knexInstance;

function isPostgreSQL(client) {
if (!client) {
return false;
}

return client === 'pg' || client === 'postgres' || client === 'postgresql';
}

// @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
Expand All @@ -10,11 +18,7 @@ function configure(dbConfig) {
var client = dbConfig.client,
pg;

dbConfig.isPostgreSQL = function () {
return client === 'pg' || client === 'postgres' || client === 'postgresql';
};

if (dbConfig.isPostgreSQL()) {
if (isPostgreSQL(client)) {
try {
pg = require('pg');
} catch (e) {
Expand Down Expand Up @@ -55,3 +59,4 @@ if (!knexInstance && config.get('database') && config.get('database').client) {
}

module.exports = knexInstance;
module.exports.isPostgreSQL = isPostgreSQL;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var config = require('../../../../config'),
models = require(config.get('paths').corePath + '/server/models'),
api = require(config.get('paths').corePath + '/server/api'),
db = require(config.get('paths').corePath + '/server/data/db/connection'),
sequence = require(config.get('paths').corePath + '/server/utils/sequence'),
moment = require('moment'),
_ = require('lodash'),
Expand Down Expand Up @@ -43,7 +44,7 @@ module.exports = function transformDatesIntoUTC(options, logger) {
return Promise.reject(new Error('skip'));
}

if (config.get('database').isPostgreSQL()) {
if (db.isPostgreSQL()) {
_private.noOffset = true;
} else if (config.get('database').client === 'mysql') {
_private.noOffset = false;
Expand Down
5 changes: 3 additions & 2 deletions core/test/unit/migration_fixture_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var should = require('should'),
configUtils = require('../utils/configUtils'),
models = require('../../server/models'),
api = require('../../server/api'),
db = require('../../server/data/db/connection'),
permissions = require('../../server/permissions'),
notifications = require('../../server/api/notifications'),
versioning = require('../../server/data/schema/versioning'),
Expand Down Expand Up @@ -967,9 +968,9 @@ describe('Fixtures', function () {
migrationsSettingsValue;

beforeEach(function () {
configUtils.config.database.isPostgreSQL = function () {
sandbox.stub(db, 'isPostgreSQL', function isPostgreSQL() {
return isPostgres;
};
});

sandbox.stub(Date.prototype, 'getTimezoneOffset', function () {
return serverTimezoneOffset;
Expand Down

0 comments on commit 34e48dc

Please sign in to comment.