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

Commit 669f09fd by Sushant Committed by GitHub

fix(sequelize/sync): show database name and match condition when sync is rejected (#8482)

1 parent 44ad6bab
...@@ -670,14 +670,13 @@ class Sequelize { ...@@ -670,14 +670,13 @@ class Sequelize {
* @return {Promise} * @return {Promise}
*/ */
sync(options) { sync(options) {
options = _.clone(options) || {}; options = _.clone(options) || {};
options.hooks = options.hooks === undefined ? true : !!options.hooks; options.hooks = options.hooks === undefined ? true : !!options.hooks;
options = _.defaults(options, this.options.sync, this.options); options = _.defaults(options, this.options.sync, this.options);
if (options.match) { if (options.match) {
if (!options.match.test(this.config.database)) { if (!options.match.test(this.config.database)) {
return Promise.reject(new Error('Database does not match sync match parameter')); return Promise.reject(new Error(`Database "${this.config.database}" does not match sync match parameter "${options.match}"`));
} }
} }
......
...@@ -987,6 +987,18 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -987,6 +987,18 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
}); });
}); });
it('fails with incorrect match condition', function() {
const sequelize = new Sequelize('cyber_bird', 'user', 'pass', {
dialect: this.sequelize.options.dialect
});
sequelize.define('Project', {title: Sequelize.STRING});
sequelize.define('Task', {title: Sequelize.STRING});
return expect(sequelize.sync({force: true, match: /$phoenix/}))
.to.be.rejectedWith('Database "cyber_bird" does not match sync match parameter "/$phoenix/"');
});
if (dialect !== 'sqlite') { if (dialect !== 'sqlite') {
it('fails with incorrect database credentials (1)', function() { it('fails with incorrect database credentials (1)', function() {
this.sequelizeWithInvalidCredentials = new Sequelize('omg', 'bar', null, _.omit(this.sequelize.options, ['host'])); this.sequelizeWithInvalidCredentials = new Sequelize('omg', 'bar', null, _.omit(this.sequelize.options, ['host']));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!