Skip to content

Commit

Permalink
馃帹 adaption from master merge
Browse files Browse the repository at this point in the history
no issue
[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent 6a97873 commit 231fea4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down Expand Up @@ -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);
}

Expand Down
42 changes: 16 additions & 26 deletions core/test/unit/migration_fixture_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;

Expand All @@ -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');
Expand All @@ -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');

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()}]));

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 () {
Expand All @@ -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)
Expand All @@ -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')}]));
Expand Down

0 comments on commit 231fea4

Please sign in to comment.