🎨 adaption from master merge

no issue
[ci skip]
This commit is contained in:
kirrg001 2016-09-15 13:02:00 +02:00 committed by Hannah Wolfe
parent 6a97873f98
commit 231fea4766
3 changed files with 22 additions and 31 deletions

View File

@ -40,7 +40,7 @@ module.exports = function transformDatesIntoUTC(options, logger) {
return sequence([
function databaseCheck() {
// we have to change the sqlite format, because it stores dates as integer
if (ServerTimezoneOffset === 0 && config.database.client === 'mysql') {
if (ServerTimezoneOffset === 0 && config.get('database').client === 'mysql') {
return Promise.reject(new Error('skip'));
}

View File

@ -1,7 +1,8 @@
var config = require('../../../../config'),
_ = require('lodash'),
models = require(config.paths.corePath + '/server/models'),
transfomDatesIntoUTC = require(config.paths.corePath + '/server/data/migration/fixtures/006/01-transform-dates-into-utc'),
models = require(config.get('paths').corePath + '/server/models'),
db = require(config.get('paths').corePath + '/server/data/db/connection'),
transfomDatesIntoUTC = require(config.get('paths').corePath + '/server/data/migration/fixtures/006/01-transform-dates-into-utc'),
Promise = require('bluebird'),
messagePrefix = 'Fix sqlite/pg format: ',
_private = {};
@ -38,14 +39,14 @@ _private.rerunDateMigration = function rerunDateMigration(options, logger) {
*/
module.exports = function fixSqliteFormat(options, logger) {
// CASE: skip this script when using mysql
if (config.database.client === 'mysql') {
if (config.get('database').client === 'mysql') {
logger.warn(messagePrefix + 'This script only runs, when using sqlite/postgres as database.');
return Promise.resolve();
}
// CASE: database is postgres, server is in ANY TZ, run 006/001 again
// we can't check the format for PG somehow, so we just run the migration again
if (config.database.isPostgreSQL()) {
if (db.isPostgreSQL()) {
return _private.rerunDateMigration(options, logger);
}

View File

@ -994,7 +994,7 @@ describe('Fixtures', function () {
it('server offset is 0 and mysql', function (done) {
migrationsSettingsValue = '{}';
configUtils.config.database.client = 'mysql';
configUtils.set('database:client', 'mysql');
updateClient({}, loggerStub)
.then(function () {
@ -1067,7 +1067,8 @@ describe('Fixtures', function () {
it('pg: server TZ is UTC, only format is changing', function (done) {
createdAt = moment(1464798678537).toDate();
configUtils.config.database.client = 'pg';
configUtils.set('database:client', 'pg');
isPostgres = true;
serverTimezoneOffset = 0;
@ -1087,7 +1088,7 @@ describe('Fixtures', function () {
it('pg: server TZ is non UTC, only format is changing', function (done) {
createdAt = moment(1464798678537).toDate();
configUtils.config.database.client = 'pg';
configUtils.set('database:client', 'pg');
isPostgres = true;
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
@ -1107,7 +1108,7 @@ describe('Fixtures', function () {
it('server offset is 0 and sqlite', function (done) {
serverTimezoneOffset = 0;
createdAt = moment(1464798678537).toDate();
configUtils.config.database.client = 'sqlite3';
configUtils.set('database:client', 'sqlite3');
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
@ -1125,13 +1126,7 @@ describe('Fixtures', function () {
it('sqlite: no UTC update, only format', function (done) {
createdAt = moment(1464798678537).toDate();
configUtils.set({
database: {
client: 'sqlite3'
}
});
configUtils.set('database:client', 'sqlite3');
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
updateClient({}, loggerStub)
@ -1154,13 +1149,7 @@ describe('Fixtures', function () {
* we expect 2016-06-01 05:00:00
*/
createdAt = moment('2016-06-01 06:00:00').toDate();
configUtils.set({
database: {
client: 'mysql'
}
});
configUtils.set('database:client', 'mysql');
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 06:00:00');
updateClient({}, loggerStub)
@ -1290,10 +1279,10 @@ describe('Fixtures', function () {
transfomDatesIntoUTCStub, rawStub, isPostgres = false, isPostgreSQLWasCalled = false;
beforeEach(function () {
configUtils.config.database.isPostgreSQL = function () {
sandbox.stub(db, 'isPostgreSQL', function isPostgreSQL() {
isPostgreSQLWasCalled = true;
return isPostgres;
};
});
sandbox.stub(Date.prototype, 'getTimezoneOffset', function () {
return serverTimezoneOffset;
@ -1328,7 +1317,7 @@ describe('Fixtures', function () {
it('sqlite and server TZ is UTC: date format is integer', function (done) {
serverTimezoneOffset = 0;
configUtils.config.database.client = 'sqlite3';
configUtils.set('database:client', 'sqlite3');
rawStub = sandbox.stub().returns(Promise.resolve([{created_at: Date.now()}]));
@ -1344,7 +1333,8 @@ describe('Fixtures', function () {
it('postgres and server TZ is UTC', function (done) {
serverTimezoneOffset = 0;
configUtils.config.database.client = 'pg';
configUtils.set('database:client', 'pg');
isPostgres = true;
updateClient({}, loggerStub)
@ -1359,7 +1349,7 @@ describe('Fixtures', function () {
});
it('postgres and server TZ is not UTC', function (done) {
configUtils.config.database.client = 'pg';
configUtils.set('database:client', 'pg');
isPostgres = true;
updateClient({}, loggerStub)
@ -1376,7 +1366,7 @@ describe('Fixtures', function () {
describe('error', function () {
it('skip mysql', function (done) {
configUtils.config.database.client = 'mysql';
configUtils.set('database:client', 'mysql');
updateClient({}, loggerStub)
.then(function () {
@ -1387,7 +1377,7 @@ describe('Fixtures', function () {
});
it('skip sqlite and non UTC server timezone', function (done) {
configUtils.config.database.client = 'sqlite3';
configUtils.set('database:client', 'sqlite3');
rawStub = sandbox.stub().returns(Promise.resolve([{created_at: moment().format('YYYY-MM-DD HH:mm:ss')}]));
updateClient({transacting: {raw:rawStub}}, loggerStub)
@ -1399,7 +1389,7 @@ describe('Fixtures', function () {
});
it('skip sqlite with UTC server timezone, but correct format', function (done) {
configUtils.config.database.client = 'sqlite3';
configUtils.set('database:client', 'sqlite3');
serverTimezoneOffset = 0;
rawStub = sandbox.stub().returns(Promise.resolve([{created_at: moment().format('YYYY-MM-DD HH:mm:ss')}]));