Who are we?

We are a group of enthousiastic people working for Nedap, a Dutch company with a single goal: solve problems.

Search
« Ruby + SOAP + Multiple servers | Main
Tuesday
May012007

InnoDB Database migration

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

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

Post very nicely written, and it contains useful facts. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement. Thanks for sharing with us.hermes replica handbags

November 24, 2010 | Unregistered CommenterMargaret

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>