modifying rake db commands to use a different mysql engine
I am trying to setup a rails 3 application on mysql cluster. I am noticing that whenever I create tables with rake db:create or rake db:migrate, the tables are created with engine=InnoDb. Since I am using MySQL cluster, this is problematic. I have to create tables with engine=NDB. I was wondering what would be the best way to modify the rake db:create and rake db:migrate logic so that it creates tables with engine=NDB instead.
开发者_开发问答Thanks/
for an existing table, you should create a migration to alter table, inside it you need to execute alter table command :
class Change < ActiveRecord::Migration
def self.up
execute('ALTER TABLE some_tables ENGINE = NDB')
end
def self.down
execute('ALTER TABLE some_tables ENGINE = innodb')
end
end
But for new schema, you can use :options option on create_table method :
create_table :some_tables, :option => 'ENGINE = NDB' do |t|
...
end
http://guides.rubyonrails.org/v3.0.3/migrations.html#creating-a-table
精彩评论