Skip to content

Commit

Permalink
Merge pull request sequelize#5273 from karthikv/postgres-timezone
Browse files Browse the repository at this point in the history
Fix setting postgres timezone while fetching hstore oids.
  • Loading branch information
janmeier committed Jan 26, 2016
2 parents 9aa3773 + 6dda277 commit ae89e84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/dialects/postgres/connection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ConnectionManager.prototype.connect = function(config) {
if (!self.sequelize.config.keepDefaultTimezone) {
var isZone = !!moment.tz.zone(self.sequelize.options.timezone);
if (isZone) {
query += 'SET client_min_messages TO warning; SET TIME ZONE \'' + self.sequelize.options.timezone + '\'';
query += 'SET client_min_messages TO warning; SET TIME ZONE \'' + self.sequelize.options.timezone + '\';';
} else {
query += 'SET client_min_messages TO warning; SET TIME ZONE INTERVAL \'' + self.sequelize.options.timezone + '\' HOUR TO MINUTE;';
}
Expand Down
15 changes: 13 additions & 2 deletions test/integration/dialects/postgres/connection-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var chai = require('chai')

if (dialect.match(/^postgres/)) {
describe('[POSTGRES] Sequelize', function() {
it('should correctly parse the moment based timezone', function() {
var options = _.extend(this.sequelize.options, { timezone: 'Asia/Kolkata', timestamps: true });
function checkTimezoneParsing(baseOptions) {
var options = _.extend({}, baseOptions, { timezone: 'Asia/Kolkata', timestamps: true });
var sequelize = Support.createSequelizeInstance(options);

var tzTable = sequelize.define('tz_table', { foo: DataTypes.STRING });
Expand All @@ -20,6 +20,17 @@ if (dialect.match(/^postgres/)) {
expect(row).to.be.not.null;
});
});
}

it('should correctly parse the moment based timezone', function() {
return checkTimezoneParsing(this.sequelize.options);
});

it('should correctly parse the moment based timezone while fetching hstore oids', function() {
// reset oids so we need to refetch them
DataTypes.HSTORE.types.postgres.oids = [];
DataTypes.HSTORE.types.postgres.array_oids = [];
return checkTimezoneParsing(this.sequelize.options);
});
});
}

0 comments on commit ae89e84

Please sign in to comment.