开发者

Heroku database rake with loop

开发者 https://www.devze.com 2023-03-14 07:46 出处:网络
I am trying to run this migration on heroku, but it hangs at the loop. puts \"0\" add_column :batches, :store_id, :integer

I am trying to run this migration on heroku, but it hangs at the loop.

puts "0"
add_column :batches, :store_id, :integer
add_column :batches, :company_id, :integer
puts "1"
for batch in Batch.all()
    puts "2"
    batch.company_id = batch.register.store.company.id.to_i
    puts "3"
    batch.store_id = batch.register.store.id.to_i
    puts "4"
    batch.save
    puts "5"
end
puts "6"

Unfortunately, I can't tell exactly where it is hanging because none of my "puts" are being shown in console. The last line I get is:

 -- add_column(:batches, :store_id, :integer)

I am not able to get any migrations with a loop working on heroku, but they all work fine locally, am I doing something wrong?

Output from heroku logs:

2011-06-20T13:58:15+00:00 app[rake.14]: Starting process with command `rake db:migrate --trace`
2011-06-20T13:58:48+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-06-20T13:58:48+00:00 app[web.1]: >> Stopping ...
2011-06-20T13:58开发者_运维百科:48+00:00 heroku[web.1]: Process exited


The problem is probably because you are not including the environment which I show below; you can also run this in heroku console

In your apps shell/terminal

heroku console

Then just run it as a block because heroku will not let you run do/end blocks

Batch.all.each {|b| b.update_attributes(:company => b.register.store.company, :store => b.register.store)}

So that should work in console unless one of those fields is nill and that is why you are going to need a rake task for erros.

Try this instead:

lib/tasks/add_bathces.rake

task :add_bathces => :environment do 
  Batch.all.each do |batch|
    if batch.register.store.comapny &&  batch.register.store
        batch.update_attributes(:company => b.register.store.company, :store => b.register.store)
    else
      puts "Store or company were nill"
    end
  end  
end
0

精彩评论

暂无评论...
验证码 换一张
取 消