Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

'rake db:migrate:redo' fails to update schema.rb

#1209

In Rails 2.1.1, the rake db:migrate:redo properly reverts the db/schema.rb file, but fails to update db/schema.rb upon migration completion.

The following commands reproduce the issue:

$ rails testing_app
$ cd testing_app
$ ./script/generate model Foo name:string
$ rake db:migrate
$ cat db/schema.rb

ActiveRecord::Schema.define(:version => 20081013165823) do

  create_table "foos", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end

$ rake db:migrate:redo
$ cat db/schema.rb

ActiveRecord::Schema.define(:version => 0) do

end

Reported by Nathaniel Bibler · October 13th, 2008 @ 06:05 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: Low

Activity

  1. Tyler Rick
    Tyler Rick

    I wasted a fair bit of time today trying to figure out why when my specs didn't have the latest changes I'd made to the schema (and were failing as a result). Finally I tracked it down to this bug.

    As a workaround, you can always do rake db:migrate:redo; rake db:schema:dump... but who wants to do that? So I decided to investigate a little further...

    If you run rake db:schema:dump --trace you will notice that although both db:rollback and db:migrate invoke db:schema:dump, only the first "invoke" results in an **Execute** db:schema:dump.

    ** Invoke db:migrate:redo (first_time)
    ** Invoke db:rollback (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute db:rollback
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment
    ** Execute db:schema:dump
    ** Invoke db:migrate (first_time)
    ** Invoke environment
    ** Execute db:migrate
    ** Invoke db:schema:dump
    ** Execute db:migrate:redo
    
    

    It turns out that Rake will only "invoke" a task once.... which works out great for tasks like "environment", which are given as a prerequisite to a lot of tasks and only actually NEED to be invoked once, but as this ticket proves, there are times when you just want to simply execute a task unconditionally without consideration as to whether it's been run already or not.

    I wish Rake provided a standard method to unconditionally invoke a task. But since it doesn't, I wrote my own invoke_again method. It's not pretty but it works. (See attached patch.)

    ...
    ** Execute db:migrate
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment
    ** Execute db:schema:dump
    ** Execute db:migrate:redo
    
    

    November 14th, 2008 @ 08:53 PM

  2. Charles
    Charles

    Thanks Tyler-

    Your patch works great, and saved me some Advil.

    December 2nd, 2008 @ 02:34 PM

  3. CancelProfileIsBroken
  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag changed from 2.1-stable, 2.1.1, bug, migration, migrations, rake to 2.1-stable 2.1.1 bug bug migration migrations rake
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 19th, 2010 @ 07:09 AM