ec176c243a
issues #6406 #6399 - all dates are stored as UTC with this commit - use moment.tz.setDefault('UTC') - add migration file to recalculate local datetimes to UTC - store all dates in same format into our three supported databases - add option to remeber migrations inside settings (core) - support DST offset for migration - ensure we force UTC in test env - run whole migration as transaction - extend: Settings.findOne function
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
var knex = require('knex'),
|
|
config = require('../../config'),
|
|
dbConfig = config.database,
|
|
knexInstance;
|
|
|
|
function configure(dbConfig) {
|
|
var client = dbConfig.client,
|
|
pg;
|
|
|
|
dbConfig.isPostgreSQL = function () {
|
|
return client === 'pg' || client === 'postgres' || client === 'postgresql';
|
|
};
|
|
|
|
if (dbConfig.isPostgreSQL()) {
|
|
try {
|
|
pg = require('pg');
|
|
} catch (e) {
|
|
pg = require('pg.js');
|
|
}
|
|
|
|
// By default PostgreSQL returns data as strings along with an OID that identifies
|
|
// its type. We're setting the parser to convert OID 20 (int8) into a javascript
|
|
// integer.
|
|
pg.types.setTypeParser(20, function (val) {
|
|
return val === null ? null : parseInt(val, 10);
|
|
});
|
|
|
|
// https://github.com/tgriesser/knex/issues/97
|
|
// this sets the timezone to UTC only for the connection!
|
|
dbConfig.pool = {
|
|
afterCreate: function (connection, callback) {
|
|
connection.query('set timezone=\'UTC\'', function (err) {
|
|
callback(err, connection);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
if (client === 'sqlite3') {
|
|
dbConfig.useNullAsDefault = dbConfig.useNullAsDefault || false;
|
|
}
|
|
|
|
if (client === 'mysql') {
|
|
dbConfig.connection.timezone = 'UTC';
|
|
}
|
|
|
|
return dbConfig;
|
|
}
|
|
|
|
if (!knexInstance && dbConfig && dbConfig.client) {
|
|
knexInstance = knex(configure(dbConfig));
|
|
}
|
|
|
|
module.exports = knexInstance;
|