-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Presently, when executing more than one ChangeColumn (or renameColumn) operation, you must use the following code (example):
renameColumn("tablename", "oldColName", "newColName"); // Only if changing the column name
changeColumn(table="tablename", columnName="newColName", columnType="string", default="", null=true, limit="20");
Neither of these functions allows for the change to be executed on a table object in the same manner the createTable function does. If an error occurs part way through a long sequence of these commands, then all subsequent changes will fail, but all previous changes have already been executed. As such, the migrate function fails to complete (up), and cannot be reverted (down) due to the database being left in a state that would allow either the up or down migration to be run. This results in manual database changes being required to bring the database back into line.
I would like to suggest that changeTable follow a similar structure as the DBMigrate createTable function:
t = changeTable(name);
t.changeColumn(columnName, columnType [newColumnName, referenceName, default, null, limit, precision, scale, addColumns]);
// ... additional change or rename column definitions would go here ...
t.change();
Note that the proposed re-definition of changeColumn adds support for renaming a column. I think it should also support adding an auto-incrementing primary key to a column.