LoginSignup
2
1

More than 5 years have passed since last update.

migrationの最新バージョンを取得する(rails)

Posted at

経緯

マイグレーションの実行状況はschema_migrationsに設定されているのは知っているが
最後に実行したバージョン(最新のバージョン)を取得する方法がなかなか見つからなかったのでメモ。

取得方法

ActiveRecord::Migrator.current_version

railsで使われていた場所

最新バージョンを取得するrakeタスクが用意されている
db:version

rails/activerecord/lib/active_record/railties/databases.rake
  desc "Retrieves the current schema version number"
  task version: [:environment, :load_config] do
    puts "Current version: #{ActiveRecord::Migrator.current_version}"
  end
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1