Rails migration: best way to retrieve current migration version

后端 未结 4 985
梦谈多话
梦谈多话 2021-01-30 03:06

Is there good way to retrieve migration version number?

I need to implement a method in a model which behave differently on and beyond a specific migration version.

4条回答
  •  日久生厌
    2021-01-30 03:27

    If you don't want to do this without loading your app you can create a script like this:

    #!/usr/bin/env ruby
    
    root = File.expand_path("../..", __FILE__)
    lines = `ls #{root}/db/migrate`
    puts lines.split("\n").last.split(" ").last.split("_").first
    

    Note the root line is because my script is in a bin dir

提交回复
热议问题