Skip to content

Commit b4d257f

Browse files
committed
Merge pull request brianc#65 from brianc/hotfix/rename-table
renameColumn not working?
2 parents 60d6262 + f214684 commit b4d257f

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

lib/table.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ Table.prototype.hasColumn = function(col) {
6060
Table.prototype.getColumn =
6161
Table.prototype.get =
6262
function(colName) {
63-
var col = this.createColumn(colName);
64-
65-
if(!this.hasColumn(col)) {
66-
throw new Error('Table ' + this._name + ' does not have a column named ' + colName);
63+
for(var i = 0; i < this.columns.length; i++) {
64+
var col = this.columns[i];
65+
if(col.name == colName) {
66+
return col;
67+
}
6768
}
68-
69-
return col;
69+
throw new Error('Table ' + this._name + ' does not have a column named ' + colName);
7070
};
7171

7272
Table.prototype.getSchema = function() {

test/dialects/alter-table-tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,21 @@ Harness.test({
121121
mysql : 'ALTER TABLE `group` CHANGE COLUMN `userId` `id` varchar(100)',
122122
params: []
123123
});
124+
125+
var UserWithSignature = Table.define({
126+
name: 'UserWithSignature',
127+
columns: [{
128+
name: 'Signature',
129+
dataType: "VARCHAR(255) NOT NULL DEFAULT 'Signature'"
130+
}]
131+
})
132+
133+
Harness.test({
134+
query: UserWithSignature.alter().renameColumn(UserWithSignature.get('Signature'), 'sig'),
135+
pg: 'ALTER TABLE "UserWithSignature" RENAME COLUMN "Signature" TO "sig"',
136+
mysql: 'ALTER TABLE `UserWithSignature` CHANGE COLUMN `Signature` `sig` VARCHAR(255) NOT NULL DEFAULT \'Signature\'',
137+
sqlite: {
138+
text : 'Sqlite cannot rename columns',
139+
throws: true
140+
}
141+
})

0 commit comments

Comments
 (0)