Rails: run rake tasks like migrations

大兔子大兔子 提交于 2019-12-08 03:00:32

问题


My dev team needs to more precisely run rake tasks. There are certain tasks that need to be only run once after a specific code change. Without getting too specific, it would be like needing to update certain existing users records after a new business rule for new users is implemented in the code.

We like how migrations use a db table for logging. Is there a similar tool for rake tasks? Can we hack Rails'/ActiveRecord's migrations system for rake tasks?

We'd prefer not to mix db-related migrations with rake tasks, so any solution that explicitly keeps these separate would be great.

Thanks.


回答1:


need to be only run once after a specific code change

update certain existing users records

These are migrations. Use migrations. Unless there's some additional constraints you didn't mention, using anything but migrations would be a hack.




回答2:


I created a gem for exactly what you need: http://eyaleizenberg.blogspot.co.il/2014/08/how-to-keep-track-of-rails-rake-tasks.html



来源:https://stackoverflow.com/questions/3671471/rails-run-rake-tasks-like-migrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!