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

Commit 68a68801 by Mick Hansen

Merge pull request #2512 from jeff-french/master

Fix for ENUM support in migration.addColumn with postgres dialect.
2 parents f387f3c7 1459d4a2
...@@ -175,17 +175,16 @@ module.exports = (function() { ...@@ -175,17 +175,16 @@ module.exports = (function() {
addColumnQuery: function(table, key, dataType) { addColumnQuery: function(table, key, dataType) {
var query = 'ALTER TABLE <%= table %> ADD COLUMN <%= attribute %>;' var query = 'ALTER TABLE <%= table %> ADD COLUMN <%= attribute %>;'
, dbDataType = this.attributeToSQL(dataType, {context: 'addColumn'})
, attribute; , attribute;
if (dataType.toString() === DataTypes.ENUM.toString()) { if ((dataType.type && dataType.type.toString() === DataTypes.ENUM.toString()) || dataType.toString() === DataTypes.ENUM.toString()) {
query = this.pgEnum(table, key, dataType) + query; query = this.pgEnum(table, key, dataType) + query;
} }
attribute = Utils._.template('<%= key %> <%= definition %>')({ attribute = Utils._.template('<%= key %> <%= definition %>')({
key: this.quoteIdentifier(key), key: this.quoteIdentifier(key),
definition: this.attributeToSQL(dataType, { definition: this.pgDataTypeMapping(table, key, dbDataType)
context: 'addColumn'
})
}); });
return Utils._.template(query)({ return Utils._.template(query)({
......
...@@ -155,8 +155,24 @@ module.exports = (function() { ...@@ -155,8 +155,24 @@ module.exports = (function() {
return query; return query;
}, },
addColumnQuery: function() { addColumnQuery: function(table, key, dataType) {
var sql = MySqlQueryGenerator.addColumnQuery.apply(this, arguments); var query = 'ALTER TABLE <%= table %> ADD <%= attribute %>;'
, attributes = {};
attributes[key] = dataType;
var fields = this.attributesToSQL(attributes, {
context: 'addColumn'
});
var attribute = Utils._.template('<%= key %> <%= definition %>')({
key: this.quoteIdentifier(key),
definition: fields[key]
});
var sql = Utils._.template(query)({
table: this.quoteTable(table),
attribute: attribute
});
return this.replaceBooleanDefaults(sql); return this.replaceBooleanDefaults(sql);
}, },
......
...@@ -248,6 +248,17 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () { ...@@ -248,6 +248,17 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
}); });
}); });
}); });
it('should work with enums (1)', function () {
return this.queryInterface.addColumn('users', 'someEnum', DataTypes.ENUM('value1', 'value2', 'value3'));
});
it('should work with enums (2)', function () {
return this.queryInterface.addColumn('users', 'someOtherEnum', {
type: DataTypes.ENUM,
values: ['value1', 'value2', 'value3']
});
});
}); });
describe('describeForeignKeys', function() { describe('describeForeignKeys', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!