DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Mickael has posted 15 posts at DZone. View Full User Profile

Converting Mysql Tables In InnoDB

07.19.2007
| 5292 views |
  • submit to reddit
        // description of your code here

class ConvertMysqlToInnodb < ActiveRecord::Migration
 def self.up
   config = ActiveRecord::Base.configurations
   begin
     STDERR.puts "Migrating all existing tables to InnoDB"
     schema = []
     select_all('SHOW TABLES').inject([]) do |schema, table|
       schema << "ALTER TABLE #{table.to_a.first.last} ENGINE=InnoDB"
     end
     schema.each { |line| execute line }
   end if config[RAILS_ENV]['adapter'] == 'mysql' unless $schema_generator
 end
source http://trac.typosphere.org/browser/trunk/db/migrate/015_convert_mysql_to_innodb.rb

 def self.down
   # don't do anything
   # this is a one-way migration, but it's not "irreversable"
   # because it doesn't change any code logic
 end
end
    

Comments

Snippets Manager replied on Tue, 2007/07/24 - 11:11am

why change MYISAM to InnoDB?