运行单个迁移文件 [英] Run a single migration file

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

问题描述

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.

解决方案

You can just run the code directly out of the ruby file:

rails console
>> require "db/migrate/20090408054532_add_foos.rb"
>> AddFoos.new.up

Note: Very old versions of rails may require AddFoos.up rather than AddFoos.new.up.

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'

Note that if you do this, it won't update the schema_migrations table, but it seems like that's what you want anyway.

Additionally, if it can't find the file you may need to use require("./db/..." or try require_relative depending on your working directory

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

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