Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement renameColumn for MySQL

  • Loading branch information...
commit 82ff7ab8b9d947de0eda1be45abe25c45a8a0c46 2 parents 0c52bae + 88b8326
@kunklejr kunklejr authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/driver/mysql.js
View
11 lib/driver/mysql.js
@@ -132,8 +132,15 @@ var MysqlDriver = Base.extend({
var sql = util.format('DROP INDEX %s ON %s', indexName, tableName);
this.runSql(sql, callback);
},
-// renameColumn: function(tableName, oldColumnName, newColumnName, callback) {
-// },
+
+ renameColumn: function(tableName, oldColumnName, newColumnName, callback) {
+ var self = this, columnTypeSql = util.format("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", tableName, oldColumnName);
+ this.all(columnTypeSql, function(err, result) {
+ var columnType = result[0].COLUMN_TYPE;
+ var alterSql = util.format("ALTER TABLE %s CHANGE %s %s %s", tableName, oldColumnName, newColumnName, columnType);
+ self.runSql(alterSql, callback);
+ });
+ },
changeColumn: function(tableName, columnName, columnSpec, callback) {
var constraint = this.createColumnDef(columnName, columnSpec);
Please sign in to comment.
Something went wrong with that request. Please try again.