Who are we?

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

Search

Entries in SQL (1)

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