开发者

Running Thor Task from Migration

I want to call a thor task from a Migration. With rake I can write

def self.up
  Rake::Task["db:rollback"].invoke
end

But how can i do this with thor? (The thor command is "thor db:rollback") (thor db:rollback is not a option, I want so see the output and the script should abort on errors)

UPDATE: The migration is called from the Thorfile

It looks like this:

require 'active_record'
class Db < Thor
  desc "migrate", "description ..."
  def migrate
    ActiveRecord::Migrator.migr开发者_如何学Cate(MIGRATIONS_PATH)
  end
end


Assuming that db:rollback refers to the rollback task of the Db class, then you can do this:

script = Db.new
script.invoke(:rollback)

You can read more in the docs: http://rdoc.info/github/wycats/thor/master/Thor/Base/ClassMethods#start-instance_method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜