Search code examples
ruby-on-railsjrubymigrationactiverecord-jdbc

Rails Schema creation problem


I am using Jruby and rails 2.2.2. My problem is I have a migration that is not being correctly written to the database schema.

Here is my migration:

class CreateNotes < ActiveRecord::Migration
  def self.up
    create_table(:notes, :options => 'ENGINE=MyISAM') do |t|
      t.string :title
      t.text :body

      t.timestamps
    end

    execute "alter table notes ADD FULLTEXT(title, body)"

end

Here is what it produces on in schema.rb

create_table "notes", :force => true do |t|
  t.string   "title"
  t.text     "body"
  t.datetime "created_at"
  t.datetime "updated_at"
end

add_index "notes", ["title", "body"], :name => "title"

I have two question:

  • How do I get 'ENGINE=MyISAM' into the schema?
  • Why did my execute statement become add_index "notes", ["title", "body"], :name => "title"? and how do I force migrations to leave it as an execute statement?

Thanks to Christian Lescuyer for the answer. However, when I tried this nothing changed. I uncommented the config.active_record... line but, my schema has not changed. I have tried this in jruby and on ruby 1.8.6 with rails 2.2.2 and edge rails and there is not changes in the schema. Can anybody tell me what I am doing wrong?


Solution

  • As I use foreign key constraints, I use the SQL format for migrations. In environment.rb:

    # Use SQL instead of Active Record's schema dumper when creating the test database.
    # This is necessary if your schema can't be completely dumped by the schema dumper,
    # like if you have constraints or database-specific column types
    config.active_record.schema_format = :sql