Posted by Bart ten Brinke Tue, 01 May 2007 21:12:50 GMT
I was looking for a migration that could convert my MyISAM tables to InnoDB, as I had mistakenly created some MyISAM tables. This sounds simple, but I wasn't able to find anything that did this. This simple migration I created, does the trick nicely.
class InnodbEngine < ActiveRecord::Migration
def self.up
tables= [ 'addresses',
'assets',
'etcetera']
for table in tables
begin
table_info = select_one "SHOW TABLE STATUS LIKE '" + table + "'"
if (table_info['Engine'] != 'InnoDB')
execute 'ALTER TABLE `' + table + '` ENGINE=InnoDB'
else
puts table + ' allready InnoDB, skipping for migration'
end
rescue
puts 'Skipping table ' + table
puts 'Table not found or InnoDB not supported.'
end
end
end
def self.down
# Not needed
end
end
