Browse files

using ALTER syntax for MySQL index creation

This addresses an issue in MySQL[1] where adding an index via CTEATE will
corrupt the casing of the table name. For example:

    CREATE TABLE `Example` (`bar` VARCHAR(1));
    CREATE INDEX `foo` ON `Example` (`bar`);

The table name after these queries will be lowercased, "example."

In my.cnf, setting `lower_case_table_names=0` does address the problem,
however, it is strongly advised against[2] under cerain circumstances.
Mac OSX in particular prefers the option to be set at `2`, which is the
underlying cause of the problem.

  • Loading branch information...
1 parent 2ac29da commit c0d9fa8ae944f9c1dda520c85672ff28bee020b5 @noazark noazark committed Sep 27, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/driver/mysql.js
2 lib/driver/mysql.js
@@ -169,7 +169,7 @@ var MysqlDriver = Base.extend({
if (!Array.isArray(columns)) {
columns = [columns];
- var sql = util.format('CREATE %s INDEX `%s` ON `%s` (`%s`)', (unique ? 'UNIQUE' : ''), indexName, tableName, columns.join('`, `'));
+ var sql = util.format('ALTER TABLE `%s` ADD %s INDEX `%s` (`%s`)', tableName, (unique ? 'UNIQUE ' : ''), indexName, columns.join('`, `'));
this.runSql(sql, callback);

0 comments on commit c0d9fa8

Please sign in to comment.