带循环的 Heroku 数据库 rake

发布于 2024-11-16 01:35:13 字数 894 浏览 1 评论 0原文

我正在尝试在 heroku 上运行此迁移,但它挂在循环中。

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"

不幸的是,我无法确切地知道它挂在哪里,因为我的“放置”都没有显示在控制台中。我得到的最后一行是:

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

我无法通过在heroku上运行的循环进行任何迁移,但它们在本地都工作正常,我做错了什么吗?

Heroku 日志的输出:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2024-11-23 01:35:13

问题可能是因为您没有包括我在下面显示的环境;你也可以在heroku控制台中运行它

在你的应用程序shell/终端

heroku console

然后将其作为一个块运行,因为heroku不会让你运行do/end块

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

所以这应该在控制台中工作,除非这些字段之一为零,这就是为什么你需要一个 rake 任务来处理错误。

试试这个:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文