Rake db:reset Changes, schema.rb Info
November 10th, 2007
DHH has updated the docs for schema.rb, to reflect the fact that schema.rb is an important file that should be kept into version control. He recommends that production apps be initialized to their schema via this file, and not from migrations.
The rake db:reset task has been changed to reflect this philosophy, it will now run the db:schema:load instead of db:migrate after first dropping then recreating your database.
Migrations, as they build up over time, become increasingly fragile, whereas schema.rb is likely consistent to the current version of your schema and many fewer steps to load. One thing to keep in mind is that schema.rb does not preserve all the same setting that migrations do - character sets, collations, and other database dependent features. If you need those, switch from having a ruby schema.rb to an SQL schema file.
Switch to SQL by uncommenting this line in environment.rb:
# config.active_record.schema_format = :sql
Sorry, comments are closed for this article.
Comments
Nathan:
I have used migrations in the past to load in initial data. Is this considered not proper in rails 2.0?
The shema.rb fie wouldn’t work, I suppose I gotta start making my own rake tasks.
Jim Lindley:
I use rake tasks – but they are not as quick or convenient in the short term as migrations are.
Joel AZEMAR:
like Nathan i use the migration for load my fixture in development environement. In fact, every migration as one fixture associate like that :
require ‘active_record/fixtures’
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles, :force => true do |t| t.string :title, :name t.timestamps end Fixtures.create_fixtures(File.join(File.dirname(FILE), “data”), “roles”) end
def self.down drop_table :roles end
end
with the newest approch my fixture doesn’t loaded :(
Jim Lindley:
Joel, you can create a custom rake task that replaces rake db:reset. Call it rake db:remigrate or the like.
There’s a free screen cast on creating custom rake tasks if you’ve never done it before: Rails Cast, Rake Tasks
Joel AZEMAR:
thanks a lot, i will be can replace my bash script :D