I have a migration that saves correctly to the database when it's run
by itself through db:migrate:up, but not when it's run with other
migrations through db:migrate.

class SetActiveOnExistingItems < ActiveRecord::Migration
  def self.up
    Item.all.each do |item|
      if item.item_status == Item::STATUS_REVIEW
        item.active = false
      elsif item.item_status == Item::STATUS_IN_PROGRESS
        item.active = false
      else
        item.active = true
      end
      puts "setting item_id = #{item.id} to active = #{item.active}"
      item.save!
      puts "setting item_id = #{item.id} to active = #{item.active}"
      item = Item.find(item.id)
      puts "setting item_id = #{item.id} to active = #{item.active}"
    end
  end

  def self.down
    Item.all.each {|item| item.active = nil; item.save(false)}
  end
end

The output during db:migrate is:
setting item_id = 1 to active = true # (this one is before the save)
setting item_id = 1 to active = true # (this one is after the save)
setting item_id = 1 to active =      # (this one is after the lookup)
...

During db:migrate:up, it works as expected:
setting item_id = 1 to active = true
setting item_id = 1 to active = true
setting item_id = 1 to active = true
...

For some reason, the data appears to not be actually committed to the
database during db:migrate, while it is during db:migrate:up. There's
no exception thrown by save!, no indicator that I can see that the
save is unsuccessful. Even if it was, why would it only be
unsuccessful during a regular migration run, and not during
db:migrate:up?

Has anyone seen this before? Do you have any idea what could cause
this?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to