不要怂,就是干,撸起袖子干!

Commit 0508bf44 by barsheshet Committed by Sushant

feat(mysql/connection-manager): do not execute SET time_zone query if keepDefaul…

…tTimezone config is true (#9358)
1 parent 20a3630b
......@@ -124,13 +124,17 @@ class ConnectionManager extends AbstractConnectionManager {
.tap (() => { debug('connection acquired'); })
.then(connection => {
return new Utils.Promise((resolve, reject) => {
// set timezone for this connection
// but named timezone are not directly supported in mysql, so get its offset first
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z') : tzOffset;
connection.query(`SET time_zone = '${tzOffset}'`, err => {
if (err) { reject(err); } else { resolve(connection); }
});
if (!this.sequelize.config.keepDefaultTimezone) {
// set timezone for this connection
// but named timezone are not directly supported in mysql, so get its offset first
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z') : tzOffset;
return connection.query(`SET time_zone = '${tzOffset}'`, err => {
if (err) { reject(err); } else { resolve(connection); }
});
}
// return connection without executing SET time_zone query
resolve(connection);
});
})
.catch(err => {
......
......@@ -150,5 +150,17 @@ if (dialect === 'mysql') {
return cm.releaseConnection(connection);
});
});
it('should acquire a valid connection when keepDefaultTimezone is true', () => {
const sequelize = Support.createSequelizeInstance({keepDefaultTimezone: true, pool: {min: 1, max: 1, handleDisconnects: true, idle: 5000}});
const cm = sequelize.connectionManager;
return sequelize
.sync()
.then(() => cm.getConnection())
.then(connection => {
expect(cm.validate(connection)).to.be.ok;
return cm.releaseConnection(connection);
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!