Rails——可以在通用 rake 任务中运行迁移方法吗?
我知道这不是最佳实践,而且很可能甚至不应该使用,因为这就是迁移的用途,但我想知道是否可以在常规 rake 任务中执行特定于迁移的命令。比如:
namespace :dummy do
task :update => :environment do
add_column :users, :deleted, :boolean, { :null => false, :default => false }
end
end
谢谢
I know this is not best practice, and most likely shouldn't even be used, as thats what migrations are used for, but I was wondering if its possible to execute migration specific commands in a regular rake task. Something like:
namespace :dummy do
task :update => :environment do
add_column :users, :deleted, :boolean, { :null => false, :default => false }
end
end
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在你的 rake 任务中运行任意伪迁移:
如果你做了很多这样的事情,请使用简写:
It is possible to run arbitrary pseudo-migrations in your rake tasks:
If you're doing a lot of that sort of thing, use short-hand:
是的,您应该这样做:
未测试,但这里重要的是包含迁移类,然后发送您希望运行的方法。
更新直接通过@tadman使用
ActiveRecord::Migration
Yes, you should do something like this:
Not tested, but the important thing here is to include the migration class and then send the method you wish to run.
UPDATED to use
ActiveRecord::Migration
directly via @tadman