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

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 { ...@@ -124,13 +124,17 @@ class ConnectionManager extends AbstractConnectionManager {
.tap (() => { debug('connection acquired'); }) .tap (() => { debug('connection acquired'); })
.then(connection => { .then(connection => {
return new Utils.Promise((resolve, reject) => { return new Utils.Promise((resolve, reject) => {
// set timezone for this connection if (!this.sequelize.config.keepDefaultTimezone) {
// but named timezone are not directly supported in mysql, so get its offset first // set timezone for this connection
let tzOffset = this.sequelize.options.timezone; // but named timezone are not directly supported in mysql, so get its offset first
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z') : tzOffset; let tzOffset = this.sequelize.options.timezone;
connection.query(`SET time_zone = '${tzOffset}'`, err => { tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z') : tzOffset;
if (err) { reject(err); } else { resolve(connection); } 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 => { .catch(err => {
......
...@@ -150,5 +150,17 @@ if (dialect === 'mysql') { ...@@ -150,5 +150,17 @@ if (dialect === 'mysql') {
return cm.releaseConnection(connection); 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!