每次迁移后你需要重新启动Heroku吗? [英] Do you need to restart Heroku after every migration?

查看:102
本文介绍了每次迁移后你需要重新启动Heroku吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了一个问题,那就是我的db方案变更没有在Heroku PG上反映出来。我仔细检查,看到移民和种子都成功了。更奇怪的是,数据库方案的改变在分阶段heroku部署(在完全相同的迁移/种子之后)上工作得很好。经过一番搜索之后,我了解到您应该在迁移后通过以下方式重新启动heroku:

  heroku restart --app = app_name 

我从来没有这样做过(我并不完全是老手,但我跑了在此之前有大量的迁移,并且从未必须重新启动heroku)。



每次迁移后,我是否需要重新启动heroku?或者,这是更多的情况下的事情?

解决方案

如果您通过迁移更改您的数据库,那么您将需要在Heroku上重新启动应用程序。当Rails以生产模式启动时,它会缓存数据库模式。迁移运行在一个正在运行的Web进程不知道的进程中。因此,为了获取所需的更改,至少需要重新启动Web进程。如果您的应用程序在部署时闲置,并且您运行了迁移,它将在应用程序启动时接收新架构。


Recently I had an issue where my db scheme change wasn't being reflected on Heroku PG. I double checked to see that both migration and seed succeeded. What was even weirder was that the db scheme change worked fine on a staging heroku deployment (after the exact same migration/seed). After some searching around, I learned that you are supposed to restart heroku after migrations via:

heroku restart --app=app_name

I've never had to do this (I'm not exactly a veteran, but I've run a good amount of migrations before and have never had to restart heroku for this particular reason).

Do I actually need to be restarting heroku after each migration? Or is this more of a case by case thing?

解决方案

If you make changes to your DB via migrations then you will need to restart the application on Heroku. When Rails starts in production mode it caches the DB schema. Migrations run in one off processes which the running web process is not aware of. So for it to pick up the changes you need to restart at least your web processes. If your application was idling when you deployed and you ran the migrations it would pick up the new schema as the app started.

这篇关于每次迁移后你需要重新启动Heroku吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆