views:

60

answers:

2

How does one create a Rails migration properly so that a table gets changed to MyISAM in MySQL? It is currently InnoDB. Running a raw execute statement will change the table, but it won't update db/schema.rb, so when the table is recreated in a testing environment, it goes back to InnoDB and my fulltext searches fail.

How do I go about changing/adding a migration so that the existing table gets modified to MyISAM and schema.rb gets updated so my db and respective test db get updated accordingly?

+1  A: 

i think that if you change your schema format (config.active_record.schema_format) from :ruby to :sql, all sql will be saved there.

i'd do some tests on a fresh app first if i were you, see how it works.

Elad Meidar
A: 

I didn't find a great way to do this. You could change your schema.rb like someone suggested and then run: rake db:schema:load, however, this will overwrite your data.

The way I did it was (assuming you are trying to convert a table called books):

  1. Save the existing data from the CLI: CREATE TABLE tmp SELECT * FROM books;

  2. In your new migration file, drop the books table and recreate it with :options => "ENGINE=MyISAM" like someone said in the comment

  3. Copy the contents back: INSERT INTO books SELECT * FROM tmp

Dex