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

Commit fde91e4c by Mick Hansen

Merge pull request #1754 from tngraessler/master

MySQL: Unique key index column names now quoted
2 parents 3a5b0206 917fbeae
...@@ -25,6 +25,8 @@ module.exports = (function() { ...@@ -25,6 +25,8 @@ module.exports = (function() {
charset: null charset: null
}, options || {}) }, options || {})
var self = this;
var query = "CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)<%= comment %> ENGINE=<%= engine %> <%= charset %> <%= collation %>" var query = "CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)<%= comment %> ENGINE=<%= engine %> <%= charset %> <%= collation %>"
, primaryKeys = [] , primaryKeys = []
, foreignKeys = {} , foreignKeys = {}
...@@ -68,7 +70,7 @@ module.exports = (function() { ...@@ -68,7 +70,7 @@ module.exports = (function() {
if (!!options.uniqueKeys) { if (!!options.uniqueKeys) {
Utils._.each(options.uniqueKeys, function(columns) { Utils._.each(options.uniqueKeys, function(columns) {
values.attributes += ", UNIQUE uniq_" + tableName + '_' + columns.fields.join('_') + " (" + columns.fields.join(', ') + ")" values.attributes += ", UNIQUE uniq_" + tableName + '_' + columns.fields.join('_') + " (" + Utils._.map(columns.fields, self.quoteIdentifier).join(", ") + ")";
}) })
} }
......
...@@ -113,6 +113,10 @@ if (Support.dialectIsMySQL()) { ...@@ -113,6 +113,10 @@ if (Support.dialectIsMySQL()) {
{ {
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES `otherTable` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION'}], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES `otherTable` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION'}],
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255), `otherId` INTEGER, FOREIGN KEY (`otherId`) REFERENCES `otherTable` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;" expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255), `otherId` INTEGER, FOREIGN KEY (`otherId`) REFERENCES `otherTable` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;"
},
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}, {uniqueKeys: [{fields: ['title', 'name']}]}],
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255), UNIQUE uniq_myTable_title_name (`title`, `name`)) ENGINE=InnoDB;"
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!