geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

MySQL: changeColumn errors out #127

Closed tbjers closed 10 years ago

tbjers commented 10 years ago

When using MySQL the changeColumn() method errors out with the following error:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE TEXT' at line 1

The query executed:

ALTER TABLE tablename ALTER COLUMN `columnname` TYPE TEXT;

This breaks in MySQL.

This is because the syntax of MySQL differs slightly from that of PostgreSQL in that it needs the statement to look as follows:

ALTER TABLE tablename ALTER COLUMN `columnname` `columnname` TEXT;

Alternatively, I think we should use modify instead:

ALTER TABLE tablename MODIFY `columnname` TEXT;

Since this involves the SQL generator I didn't want to bumble about in the code making changes and create a PR since I do not have the type of grasp of Model that you guys do. I think the right thing to do here is detect the driver for the specific table and then switch based on driver to generate the proper statement.

This stemmed from an attempt to change a column type in a migration for Geddy. Full information for this specific migration can be found here: https://gist.github.com/tbjers/d18be8bcc5ec270dc0d9

mde commented 10 years ago

Fixed in 250ef368f144c4d3c3ad6d52a4e580178426e518, pushed to NPM in v0.4.8. Thanks for catching this!