开发者

modifying rake db commands to use a different mysql engine

开发者 https://www.devze.com 2023-04-11 01:26 出处:网络
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 u

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

0

精彩评论

暂无评论...
验证码 换一张
取 消