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

Commit e076f478 by Mick Hansen

refactor(mysql/enum): remove support for ci enums in mysql

1 parent b206ebff
...@@ -518,27 +518,6 @@ module.exports = (function() { ...@@ -518,27 +518,6 @@ module.exports = (function() {
} }
}); });
for (var attrName in this.Model.rawAttributes) {
if (self.Model.rawAttributes.hasOwnProperty(attrName)) {
var definition = this.Model.rawAttributes[attrName]
, isEnum = definition.type.toString() === DataTypes.ENUM.toString()
, isMySQL = ['mysql', 'mariadb'].indexOf(this.Model.modelManager.sequelize.options.dialect) !== -1
, ciCollation = !!this.Model.options.collate && this.Model.options.collate.match(/_ci$/i)
, valueOutOfScope;
// Unfortunately for MySQL CI collation we need to map/lowercase values again
if (isEnum && isMySQL && ciCollation && (attrName in values) && values[attrName]) {
var scopeIndex = (definition.values || []).map(function(d) { return d.toLowerCase(); }).indexOf(values[attrName].toLowerCase());
valueOutOfScope = scopeIndex === -1;
// We'll return what the actual case will be, since a simple SELECT query would do the same...
if (!valueOutOfScope) {
values[attrName] = definition.values[scopeIndex];
}
}
}
}
if (updatedAtAttr && !options.silent) { if (updatedAtAttr && !options.silent) {
values[updatedAtAttr] = self.Model.__getTimestamp(updatedAtAttr); values[updatedAtAttr] = self.Model.__getTimestamp(updatedAtAttr);
} }
...@@ -559,7 +538,7 @@ module.exports = (function() { ...@@ -559,7 +538,7 @@ module.exports = (function() {
var identifier = self.primaryKeyValues; var identifier = self.primaryKeyValues;
if (identifier) { if (identifier) {
for (attrName in identifier) { for (var attrName in identifier) {
// Field name mapping // Field name mapping
var rawAttribute = self.Model.rawAttributes[attrName]; var rawAttribute = self.Model.rawAttributes[attrName];
if (rawAttribute.field && rawAttribute.field !== rawAttribute.fieldName) { if (rawAttribute.field && rawAttribute.field !== rawAttribute.fieldName) {
......
...@@ -78,58 +78,6 @@ if (Support.dialectIsMySQL()) { ...@@ -78,58 +78,6 @@ if (Support.dialectIsMySQL()) {
}); });
}); });
describe('validations', function() {
describe('enums', function() {
it('enum data type should be case insensitive if my collation allows it', function(done) {
var User = this.sequelize.define('User' + config.rand(), {
mood: {
type: DataTypes.ENUM,
values: ['HAPPY', 'sad', 'WhatEver']
}
}, {
collate: 'utf8_general_ci'
});
User.sync({ force: true }).success(function() {
User.create({mood: 'happy'}).success(function(user) {
expect(user).to.exist;
expect(user.mood).to.equal('HAPPY');
var u = User.build({mood: 'SAD'});
u.save().success(function(_user) {
expect(_user).to.exist;
expect(_user.mood).to.equal('sad');
done();
});
});
});
});
it('enum data type should be case sensitive if my collation enforces it', function(done) {
var User = this.sequelize.define('User' + config.rand(), {
mood: {
type: DataTypes.ENUM,
values: ['HAPPY', 'sad', 'WhatEver']
}
}, {
collate: 'latin1_bin'
});
User.sync({ force: true }).success(function() {
User.create({mood: 'happy'}).error(function(err) {
expect(err).to.be.instanceOf(Error);
expect(err.get('mood')[0].message).to.equal('Value "happy" for ENUM mood is out of allowed scope. Allowed values: HAPPY, sad, WhatEver');
var u = User.build({mood: 'SAD'});
u.save().error(function(err) {
expect(err).to.be.instanceOf(Error);
expect(err.get('mood')[0].message).to.equal('Value "SAD" for ENUM mood is out of allowed scope. Allowed values: HAPPY, sad, WhatEver');
done();
});
});
});
});
});
});
describe('primaryKeys', function() { describe('primaryKeys', function() {
it('determines the correct primaryKeys', function(done) { it('determines the correct primaryKeys', function(done) {
var User = this.sequelize.define('User' + config.rand(), { var User = this.sequelize.define('User' + config.rand(), {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!