mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
parent
6275fdbb25
commit
8115d83782
15 changed files with 15 additions and 182 deletions
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
|
@ -100,7 +100,7 @@ Any other info e.g. Why do you consider this to be a bug? What did you expect to
|
|||
* Ghost Version: master (latest commit: a761de2079dca4df49567b1bddac492f25033985)
|
||||
* Node Version: 4.4.7
|
||||
* Browser: Chrome 48.0.2564.109 on Mac OS X 10.10.4
|
||||
* Database: SQLite / MySQL / postgres
|
||||
* Database: SQLite / MySQL
|
||||
```
|
||||
|
||||
<a name="features"></a>
|
||||
|
|
|
@ -10,8 +10,6 @@ cache:
|
|||
- node_modules
|
||||
- core/client/node_modules
|
||||
- core/client/bower_components
|
||||
addons:
|
||||
postgresql: "9.3"
|
||||
env:
|
||||
global:
|
||||
- GITHUB_OAUTH_KEY=003a44d58f12089d0c0261338298af3813330949
|
||||
|
@ -20,7 +18,6 @@ env:
|
|||
matrix:
|
||||
- DB=sqlite3 NODE_ENV=testing
|
||||
- DB=mysql NODE_ENV=testing-mysql
|
||||
- DB=pg NODE_ENV=testing-pg
|
||||
matrix:
|
||||
include:
|
||||
- node_js: "4"
|
||||
|
@ -31,7 +28,6 @@ branches:
|
|||
- /^greenkeeper-.+$/
|
||||
before_install:
|
||||
- if [ $DB == "mysql" ]; then mysql -e 'create database ghost_testing'; fi
|
||||
- if [ $DB == "pg" ]; then psql -c 'create database ghost_testing;' -U postgres; fi
|
||||
after_success:
|
||||
- |
|
||||
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
|
||||
|
|
|
@ -561,8 +561,8 @@ var overrides = require('./core/server/overrides'),
|
|||
// `grunt test:integration/api/api_tags_spec.js`
|
||||
//
|
||||
// Their purpose is to test that both the api and models behave as expected when the database layer is involved.
|
||||
// These tests are run against sqlite3, mysql and pg on travis and ensure that differences between the databases
|
||||
// don't cause bugs. At present, pg often fails and is not officially supported.
|
||||
// These tests are run against sqlite3 and mysql on travis and ensure that differences between the databases
|
||||
// don't cause bugs.
|
||||
//
|
||||
// A coverage report can be generated for these tests using the `grunt test-coverage` task.
|
||||
grunt.registerTask('test-integration', 'Run integration tests (mocha + db access)',
|
||||
|
|
|
@ -91,7 +91,7 @@ AppSandbox.prototype.loadModule = function loadModuleSandboxed(modulePath) {
|
|||
};
|
||||
|
||||
AppSandbox.defaults = {
|
||||
blacklist: ['knex', 'fs', 'http', 'sqlite3', 'pg', 'mysql', 'ghost']
|
||||
blacklist: ['knex', 'fs', 'http', 'sqlite3', 'mysql', 'ghost']
|
||||
};
|
||||
|
||||
module.exports = AppSandbox;
|
||||
|
|
17
core/server/config/env/config.testing-pg.json
vendored
17
core/server/config/env/config.testing-pg.json
vendored
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"url": "http://127.0.0.1:2369",
|
||||
"server": {
|
||||
"port": 2369
|
||||
},
|
||||
"database": {
|
||||
"client": "pg",
|
||||
"connection": {
|
||||
"host" : "127.0.0.1",
|
||||
"user" : "postgres",
|
||||
"password" : "",
|
||||
"database" : "ghost_testing",
|
||||
"charset" : "utf8"
|
||||
}
|
||||
},
|
||||
"logging": false
|
||||
}
|
|
@ -2,46 +2,12 @@ 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
|
||||
// - bring dynamic into this file (db.connect())
|
||||
function configure(dbConfig) {
|
||||
var client = dbConfig.client,
|
||||
pg;
|
||||
|
||||
if (isPostgreSQL(client)) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
var client = dbConfig.client;
|
||||
|
||||
if (client === 'sqlite3') {
|
||||
dbConfig.useNullAsDefault = dbConfig.useNullAsDefault || false;
|
||||
|
@ -59,4 +25,3 @@ if (!knexInstance && config.get('database') && config.get('database').client) {
|
|||
}
|
||||
|
||||
module.exports = knexInstance;
|
||||
module.exports.isPostgreSQL = isPostgreSQL;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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'),
|
||||
|
@ -27,7 +26,6 @@ _private.addOffset = function addOffset(date) {
|
|||
};
|
||||
|
||||
/**
|
||||
* postgres: stores dates with offset, so it's enough to force timezone UTC in the db connection (see data/db/connection.js)
|
||||
* sqlite: stores UTC timestamps, but we will normalize the format to YYYY-MM-DD HH:mm:ss
|
||||
*/
|
||||
module.exports = function transformDatesIntoUTC(options, logger) {
|
||||
|
@ -44,9 +42,7 @@ module.exports = function transformDatesIntoUTC(options, logger) {
|
|||
return Promise.reject(new Error('skip'));
|
||||
}
|
||||
|
||||
if (db.isPostgreSQL()) {
|
||||
_private.noOffset = true;
|
||||
} else if (config.get('database').client === 'mysql') {
|
||||
if (config.get('database').client === 'mysql') {
|
||||
_private.noOffset = false;
|
||||
} else if (config.get('database').client === 'sqlite3') {
|
||||
_private.noOffset = true;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
var config = require('../../../../config'),
|
||||
_ = require('lodash'),
|
||||
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: ',
|
||||
messagePrefix = 'Fix sqlite format: ',
|
||||
_private = {};
|
||||
|
||||
_private.rerunDateMigration = function rerunDateMigration(options, logger) {
|
||||
|
@ -34,22 +33,16 @@ _private.rerunDateMigration = function rerunDateMigration(options, logger) {
|
|||
};
|
||||
|
||||
/**
|
||||
* this migration script is a very special one for people who run their server in UTC and use sqlite3 or run their server in any TZ and use postgres
|
||||
* this migration script is a very special one for people who run their server in UTC and use sqlite3
|
||||
* 006/01-transform-dates-into-utc had a bug for this case, see what happen because of this bug https://github.com/TryGhost/Ghost/issues/7192
|
||||
*/
|
||||
module.exports = function fixSqliteFormat(options, logger) {
|
||||
// CASE: skip this script when using mysql
|
||||
if (config.get('database').client === 'mysql') {
|
||||
logger.warn(messagePrefix + 'This script only runs, when using sqlite/postgres as database.');
|
||||
logger.warn(messagePrefix + 'This script only runs, when using sqlite 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 (db.isPostgreSQL()) {
|
||||
return _private.rerunDateMigration(options, logger);
|
||||
}
|
||||
|
||||
// CASE: sqlite3 and server is UTC, we check if the date migration was already running
|
||||
return options.transacting.raw('select created_at from users')
|
||||
.then(function (users) {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
var sqlite3 = require('./sqlite3'),
|
||||
mysql = require('./mysql'),
|
||||
pg = require('./pg');
|
||||
mysql = require('./mysql');
|
||||
|
||||
module.exports = {
|
||||
sqlite3: sqlite3,
|
||||
mysql: mysql,
|
||||
pg: pg,
|
||||
postgres: pg,
|
||||
postgresql: pg
|
||||
mysql: mysql
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// - node version
|
||||
// - npm version
|
||||
// - env - production or development
|
||||
// - database type - SQLite, MySQL, PostgreSQL
|
||||
// - database type - SQLite, MySQL
|
||||
// - email transport - mail.options.service, or otherwise mail.transport
|
||||
// - created date - database creation date
|
||||
// - post count - total number of posts
|
||||
|
|
|
@ -38,8 +38,6 @@ describe('User API', function () {
|
|||
describe('As Owner', function () {
|
||||
describe('Browse', function () {
|
||||
it('returns dates in ISO 8601 format', function (done) {
|
||||
// @TODO: postgres returns for default oder (last_login DESC) something else then sqlite
|
||||
// @TODO: maybe related to https://github.com/TryGhost/Ghost/issues/6104
|
||||
request.get(testUtils.API.getApiQuery('users/?order=id%20ASC'))
|
||||
.set('Authorization', 'Bearer ' + ownerAccessToken)
|
||||
.expect('Content-Type', /json/)
|
||||
|
|
|
@ -34,7 +34,7 @@ describe('Update Check', function () {
|
|||
data.ghost_version.should.equal(packageInfo.version);
|
||||
data.node_version.should.equal(process.versions.node);
|
||||
data.env.should.equal(process.env.NODE_ENV);
|
||||
data.database_type.should.match(/sqlite3|pg|mysql/);
|
||||
data.database_type.should.match(/sqlite3|mysql/);
|
||||
data.blog_id.should.be.a.String();
|
||||
data.blog_id.should.not.be.empty();
|
||||
data.theme.should.be.equal('casper');
|
||||
|
|
|
@ -9,7 +9,6 @@ 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'),
|
||||
|
@ -955,8 +954,6 @@ describe('Fixtures', function () {
|
|||
});
|
||||
|
||||
describe('Tasks:', function () {
|
||||
var isPostgres = false;
|
||||
|
||||
it('should have tasks for 006', function () {
|
||||
should.exist(fixtures006);
|
||||
fixtures006.should.be.an.Array().with.lengthOf(1);
|
||||
|
@ -968,19 +965,11 @@ describe('Fixtures', function () {
|
|||
migrationsSettingsValue;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox.stub(db, 'isPostgreSQL', function isPostgreSQL() {
|
||||
return isPostgres;
|
||||
});
|
||||
|
||||
sandbox.stub(Date.prototype, 'getTimezoneOffset', function () {
|
||||
return serverTimezoneOffset;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
isPostgres = false;
|
||||
});
|
||||
|
||||
describe('error cases', function () {
|
||||
before(function () {
|
||||
serverTimezoneOffset = 0;
|
||||
|
@ -1065,46 +1054,6 @@ describe('Fixtures', function () {
|
|||
sandbox.stub(api.settings, 'updateSettingsCache').returns(Promise.resolve({}));
|
||||
});
|
||||
|
||||
it('pg: server TZ is UTC, only format is changing', function (done) {
|
||||
createdAt = moment(1464798678537).toDate();
|
||||
configUtils.set('database:client', 'pg');
|
||||
|
||||
isPostgres = true;
|
||||
serverTimezoneOffset = 0;
|
||||
|
||||
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
|
||||
|
||||
updateClient({}, loggerStub)
|
||||
.then(function () {
|
||||
_.each(newModels, function (model) {
|
||||
moment(model.get('created_at')).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
|
||||
});
|
||||
|
||||
migrationsSettingsWasUpdated.should.eql(true);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('pg: server TZ is non UTC, only format is changing', function (done) {
|
||||
createdAt = moment(1464798678537).toDate();
|
||||
configUtils.set('database:client', 'pg');
|
||||
isPostgres = true;
|
||||
|
||||
moment(createdAt).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
|
||||
|
||||
updateClient({}, loggerStub)
|
||||
.then(function () {
|
||||
_.each(newModels, function (model) {
|
||||
moment(model.get('created_at')).format('YYYY-MM-DD HH:mm:ss').should.eql('2016-06-01 16:31:18');
|
||||
});
|
||||
|
||||
migrationsSettingsWasUpdated.should.eql(true);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('server offset is 0 and sqlite', function (done) {
|
||||
serverTimezoneOffset = 0;
|
||||
createdAt = moment(1464798678537).toDate();
|
||||
|
@ -1276,14 +1225,9 @@ describe('Fixtures', function () {
|
|||
describe('01-fix-sqlite-pg-format', function () {
|
||||
var updateClient = rewire('../../server/data/migration/fixtures/008/01-fix-sqlite-pg-format'),
|
||||
serverTimezoneOffset = 60,
|
||||
transfomDatesIntoUTCStub, rawStub, isPostgres = false, isPostgreSQLWasCalled = false;
|
||||
transfomDatesIntoUTCStub, rawStub;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox.stub(db, 'isPostgreSQL', function isPostgreSQL() {
|
||||
isPostgreSQLWasCalled = true;
|
||||
return isPostgres;
|
||||
});
|
||||
|
||||
sandbox.stub(Date.prototype, 'getTimezoneOffset', function () {
|
||||
return serverTimezoneOffset;
|
||||
});
|
||||
|
@ -1291,8 +1235,6 @@ describe('Fixtures', function () {
|
|||
|
||||
afterEach(function () {
|
||||
serverTimezoneOffset = 60;
|
||||
isPostgres = false;
|
||||
isPostgreSQLWasCalled = false;
|
||||
});
|
||||
|
||||
describe('success', function () {
|
||||
|
@ -1330,38 +1272,6 @@ describe('Fixtures', function () {
|
|||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('postgres and server TZ is UTC', function (done) {
|
||||
serverTimezoneOffset = 0;
|
||||
configUtils.set('database:client', 'pg');
|
||||
|
||||
isPostgres = true;
|
||||
|
||||
updateClient({}, loggerStub)
|
||||
.then(function () {
|
||||
isPostgreSQLWasCalled.should.eql(true);
|
||||
models.Settings.edit.callCount.should.eql(1);
|
||||
models.Settings.findOne.callCount.should.eql(1);
|
||||
transfomDatesIntoUTCStub.callCount.should.eql(1);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('postgres and server TZ is not UTC', function (done) {
|
||||
configUtils.set('database:client', 'pg');
|
||||
isPostgres = true;
|
||||
|
||||
updateClient({}, loggerStub)
|
||||
.then(function () {
|
||||
isPostgreSQLWasCalled.should.eql(true);
|
||||
models.Settings.edit.callCount.should.eql(1);
|
||||
models.Settings.findOne.callCount.should.eql(1);
|
||||
transfomDatesIntoUTCStub.callCount.should.eql(1);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error', function () {
|
||||
|
|
|
@ -84,7 +84,6 @@ fixtures = {
|
|||
}));
|
||||
}).then(function () {
|
||||
return Promise.all([
|
||||
// PostgreSQL can return results in any order
|
||||
db.knex('posts').orderBy('id', 'asc').select('id'),
|
||||
db.knex('tags').select('id')
|
||||
]);
|
||||
|
@ -162,7 +161,6 @@ fixtures = {
|
|||
max = max || 50;
|
||||
|
||||
return Promise.all([
|
||||
// PostgreSQL can return results in any order
|
||||
db.knex('posts').orderBy('id', 'asc').select('id'),
|
||||
db.knex('tags').select('id', 'name')
|
||||
]).then(function (results) {
|
||||
|
|
|
@ -85,8 +85,7 @@
|
|||
"xml": "1.0.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"mysql": "2.1.1",
|
||||
"pg": "4.1.1"
|
||||
"mysql": "2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gh-contrib-list": "0.1.2",
|
||||
|
@ -127,7 +126,6 @@
|
|||
"glob",
|
||||
"mysql",
|
||||
"nodemailer",
|
||||
"pg",
|
||||
"showdown-ghost"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue