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

Commit a337a367 by Mick Hansen

Merge pull request #1115 from mulderr/master

use uuid type for uuids by default, let the dialect specify whats best - fixes #1112
2 parents 1fac401a 77d11b27
...@@ -188,7 +188,7 @@ module.exports = { ...@@ -188,7 +188,7 @@ module.exports = {
FLOAT: FLOAT, FLOAT: FLOAT,
NOW: 'NOW', NOW: 'NOW',
BLOB: BLOB, BLOB: BLOB,
UUID: 'CHAR(36)', UUID: 'UUID',
UUIDV1: 'UUIDV1', UUIDV1: 'UUIDV1',
UUIDV4: 'UUIDV4', UUIDV4: 'UUIDV4',
......
...@@ -50,7 +50,7 @@ module.exports = (function() { ...@@ -50,7 +50,7 @@ module.exports = (function() {
for (var attr in attributes) { for (var attr in attributes) {
if (attributes.hasOwnProperty(attr)) { if (attributes.hasOwnProperty(attr)) {
var dataType = attributes[attr] var dataType = this.mysqlDataTypeMapping(tableName, attr, attributes[attr])
if (Utils._.includes(dataType, 'PRIMARY KEY')) { if (Utils._.includes(dataType, 'PRIMARY KEY')) {
primaryKeys.push(attr) primaryKeys.push(attr)
...@@ -117,7 +117,7 @@ module.exports = (function() { ...@@ -117,7 +117,7 @@ module.exports = (function() {
attrString.push(Utils._.template('`<%= attrName %>` <%= definition %>')({ attrString.push(Utils._.template('`<%= attrName %>` <%= definition %>')({
attrName: attrName, attrName: attrName,
definition: definition definition: this.mysqlDataTypeMapping(tableName, attrName, definition)
})) }))
} }
...@@ -496,6 +496,14 @@ module.exports = (function() { ...@@ -496,6 +496,14 @@ module.exports = (function() {
*/ */
dropForeignKeyQuery: function(tableName, foreignKey) { dropForeignKeyQuery: function(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteIdentifier(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';' return 'ALTER TABLE ' + this.quoteIdentifier(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';'
},
mysqlDataTypeMapping: function(tableName, attr, dataType) {
if (Utils._.includes(dataType, 'UUID')) {
dataType = dataType.replace(/UUID/, 'CHAR(36) BINARY')
}
return dataType
} }
} }
......
...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
[Sequelize.TEXT, 'TEXT', 'TEXT'], [Sequelize.TEXT, 'TEXT', 'TEXT'],
[Sequelize.DATE, 'DATE', 'DATETIME'], [Sequelize.DATE, 'DATE', 'DATETIME'],
[Sequelize.NOW, 'NOW', 'NOW'], [Sequelize.NOW, 'NOW', 'NOW'],
[Sequelize.UUID, 'UUID', 'CHAR(36)'], [Sequelize.UUID, 'UUID', 'UUID'],
[Sequelize.BOOLEAN, 'BOOLEAN', 'TINYINT(1)'], [Sequelize.BOOLEAN, 'BOOLEAN', 'TINYINT(1)'],
[Sequelize.BLOB, 'BLOB', 'BLOB'], [Sequelize.BLOB, 'BLOB', 'BLOB'],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!