How to make Rails ActiveRecord::Migration default to MyISAM

Some people perfer InnoDB, other MyISAM. This post ain't about a MySQL-Engine flame war but about letting people choice.

Fact is, the excellent Migration system shipped with rubyonrails and ActiveRecord is defaulting to InnoDB. The doc shows how you can specify the engine on each create_table statement. but then your migration are mysql-only because these engine options will not be supported by sqlite or MSSQL. and I dont want to copy/paste these options to all of my create table. I want to change the default.

unfortunately Rails supply no options for it

fortunately Rails is built on Ruby.

so you can simply overwrite the proper method by adding it to your config/environment.rb

module ActiveRecord
        module ConnectionAdapters
                class MysqlAdapter < AbstractAdapter
                        def create_table(table_name, options = {}) #:nodoc:
                                super(table_name, options.reverse_merge(:options => "ENGINE=MyISAM"))
                        end
                end
        end
end

Tags , , , , , , , , ,

Posted in , , | Posted on 08 Apr 2009 13:56by somekool | 2 comments

Subscribe

Personal Links

Tags

Categories

Archives

my Xbox 360 gamertag

my last twitter posts

Copyright © Mathieu Jobin's Life and Thoughts

Tech Blue designed by Hive Designs • Ported by Free WordPress Themes and Frédéric de Villamil Powered by Typo