Rails 插件在启动时运行迁移? [英] Rails plugin to run migrations on startup?

查看:56
本文介绍了Rails 插件在启动时运行迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有插件可以让 Rails 在启动时通过 db:migrate 运行?我正在寻找一种不涉及通过 shell 调用 Rake 任务的解决方案;所以,没有system('rake db:migrate')".

Is there a plugin available to have Rails run through a db:migrate on startup? I'm looking for a solution that doesn't involve calling out to the Rake task via the shell; so, no "system('rake db:migrate')".

我可以很容易地编写自己的插件来做到这一点,但我认为如果存在的话,最好使用/改进现有的 migrate-on-init 插件.

I can readily write my own plugin to do this, but figured it would be better to use/improve an existing migrate-on-init plugin if one exists.

推荐答案

这是我在 jRuby 上的 Rails 3.2 工作版本:

Here is my working version for Rails 3.2 on jRuby:

config.after_initialize do
  ActiveRecord::Migrator.migrate(Rails.root.join("db/migrate"), nil)
end

这篇关于Rails 插件在启动时运行迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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