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

Commit c463314d by Gabe Gorelick Committed by Sushant

feat(postgres): allow customizing client_min_messages (#10448)

1 parent 149d381b
......@@ -177,12 +177,16 @@ class ConnectionManager extends AbstractConnectionManager {
query += 'SET standard_conforming_strings=on;';
}
if (this.sequelize.options.clientMinMessages !== false) {
query += `SET client_min_messages TO ${this.sequelize.options.clientMinMessages};`;
}
if (!this.sequelize.config.keepDefaultTimezone) {
const isZone = !!moment.tz.zone(this.sequelize.options.timezone);
if (isZone) {
query += `SET client_min_messages TO warning; SET TIME ZONE '${this.sequelize.options.timezone}';`;
query += `SET TIME ZONE '${this.sequelize.options.timezone}';`;
} else {
query += `SET client_min_messages TO warning; SET TIME ZONE INTERVAL '${this.sequelize.options.timezone}' HOUR TO MINUTE;`;
query += `SET TIME ZONE INTERVAL '${this.sequelize.options.timezone}' HOUR TO MINUTE;`;
}
}
......
......@@ -70,6 +70,7 @@ class Sequelize {
* @param {Object} [options.set={}] Default options for sequelize.set
* @param {Object} [options.sync={}] Default options for sequelize.sync
* @param {string} [options.timezone='+00:00'] The timezone used when converting a date from the database into a JavaScript date. The timezone is also used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP and other time related functions have in the right timezone. For best cross platform performance use the format +/-HH:MM. Will also accept string versions of timezones used by moment.js (e.g. 'America/Los_Angeles'); this is useful to capture daylight savings time changes.
* @param {string|boolean} [options.clientMinMessages='warning'] The PostgreSQL `client_min_messages` session parameter. Set to `false` to not override the database's default.
* @param {Function} [options.logging=console.log] A function that gets executed every time Sequelize would log something.
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean} [options.omitNull=false] A flag that defines if null values should be passed to SQL queries or not.
......@@ -156,6 +157,7 @@ class Sequelize {
query: {},
sync: {},
timezone: '+00:00',
clientMinMessages: 'warning',
logging: console.log,
omitNull: false,
native: false,
......
......@@ -23,6 +23,30 @@ if (dialect.match(/^postgres/)) {
it('should correctly parse the moment based timezone while fetching hstore oids', function() {
return checkTimezoneParsing(this.sequelize.options);
});
it('should set client_min_messages to warning by default', () => {
return Support.sequelize.query('SHOW client_min_messages')
.then(result => {
expect(result[0].client_min_messages).to.equal('warning');
});
});
it('should allow overriding client_min_messages', () => {
const sequelize = Support.createSequelizeInstance({ clientMinMessages: 'ERROR' });
return sequelize.query('SHOW client_min_messages')
.then(result => {
expect(result[0].client_min_messages).to.equal('error');
});
});
it('should not set client_min_messages if clientMinMessages is false', () => {
const sequelize = Support.createSequelizeInstance({ clientMinMessages: false });
return sequelize.query('SHOW client_min_messages')
.then(result => {
// `notice` is Postgres's default
expect(result[0].client_min_messages).to.equal('notice');
});
});
});
describe('Dynamic OIDs', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!