Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 846
Josh Moore Avatar asked Dec 20 '08 07:12

Josh Moore


2 Answers

I too expected to see a new .sql file appear after a "rake db:migrate", once I set

config.active_record.schema_format = :sql

in config/environment.rb.

Apparently that's not how it works, however. I have to do this explicitly to get a db/[development|test|production]_structure.sql file:

rake db:structure:dump
like image 132
Pete TerMaat Avatar answered Nov 02 '22 23:11

Pete TerMaat


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
like image 40
Christian Lescuyer Avatar answered Nov 02 '22 23:11

Christian Lescuyer