Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

ActiveRecordのmigration時にSQLのエンジンを選択する

たとえば、検索エンジンにmroongaを追加したい場合は
既存のdb/migrationの当該ファイルにoptions: "ENGINE = mroonga"を追加します

class CreateProfessors < ActiveRecord::Migration
  def change
    create_table :professors  ,options: "ENGINE = mroonga" do |t|
...
   end
...
end

これが終わったあとに

$ rake db:migrate:reset
$ rake db:seed

としてあげればよいです。

すでに動いているシステムの場合、上を実行すると再度作り直しになります。

その場合は

$ rails g use_mroonga_in_professors_table

として、別テーブルを作り

class UseMroongaInProfessorsTable < ActiveRecord::Migration
  def change
    execute <<-SQL
ALTER TABLE professors ENGINE = mroonga DEFAULT CHARSET utf8;
    SQL
   end
...
end

と別のカラムを追加してあげればよいです。