本文介绍了运行一个迁移文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法来运行单个迁移?我不想迁移到某个版本,而只想运行一个特定的版本.
Is there an easy way to run a single migration? I don't want to migrate to a certain version I just want to run a specific one.
推荐答案
您可以直接在ruby文件中运行代码:
You can just run the code directly out of the ruby file:
rails console
>> require "db/migrate/20090408054532_add_foos.rb"
>> AddFoos.up
注意:较新版本的rails可能需要AddFoos.new.up
而不是AddFoos.up
.
Note: newer versions of rails may require AddFoos.new.up
rather than AddFoos.up
.
另一种方法(不带IRB)依赖于require需要返回一个类名数组的事实:
An alternative way (without IRB) which relies on the fact that require returns an array of class names:
script/runner 'require("db/migrate/20090408054532_add_foos.rb").first.constantize.up'
请注意,如果执行此操作,它可能不会更新schema_migrations
表,但是无论如何,这似乎就是您想要的.
Note that if you do this, it probably won't update the schema_migrations
table, but it seems like that's what you want anyway.
这篇关于运行一个迁移文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!