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

Commit 9e7487a5 by Cezar Berea Committed by Sushant

Show a reasonable message when column is missing in renameColumn (#7343)

This fixes #6606
1 parent 1f8348fb
# Future
- [FIXED] Show a reasonable message when using renameColumn with a missing column [#6606](https://github.com/sequelize/sequelize/issues/6606)
- [PERFORMANCE] more efficient array handing for certain large queries [#7175](https://github.com/sequelize/sequelize/pull/7175)
- [FIXED] Add `unique` indexes defined via options to `rawAttributes` [#7196]
- [FIXED] Removed support where `order` value is string and interpreted as `Sequelize.literal()`. [#6935](https://github.com/sequelize/sequelize/issues/6935)
......
......@@ -373,6 +373,10 @@ class QueryInterface {
renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
options = options || {};
return this.describeTable(tableName, options).then(data => {
if (!data[attrNameBefore]) {
throw new Error('Table ' + tableName + ' doesn\'t have the column ' + attrNameBefore);
}
data = data[attrNameBefore] || {};
const _options = {};
......
......@@ -421,6 +421,19 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
expect(table).to.not.have.property('fruitId');
});
});
it('shows a reasonable error message when column is missing', function() {
var self = this;
var Users = self.sequelize.define('_Users', {
username: DataTypes.STRING
}, { freezeTableName: true });
var outcome = Users.sync({ force: true }).then(function() {
return self.queryInterface.renameColumn('_Users', 'email', 'pseudo');
});
return expect(outcome).to.be.rejectedWith('Table _Users doesn\'t have the column email');
});
});
describe('changeColumn', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!