1
0

More than 1 year has passed since last update.

Railsで使用しているDBの情報を取得する

Last updated at Posted at 2022-02-22

はじめに

rails console とかで今使っているDBの情報をパパッと表示したいと思って調べたら出てきたのでメモ代わりに書き出します。

結論

connection_db_config メソッドを使う(connection_config メソッドもあるが、こちらはRails 6.2で Deprecated となっている)

確認方法

ここではirbで確認してみる。

このようにDBの接続状況が DatabaseConfigurations::HashConfig オブジェクトで返ってくる。ちなみに connection_config メソッドでは Hash オブジェクトで返ってきていた。

irb(main):001:0> ActiveRecord::Base.connection_db_config
=> 
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fffe98d16c0
 @configuration_hash={:adapter=>"sqlite3", :pool=>5, :timeout=>5000, :database=>"db/development.sqlite3"},
 @env_name="development",
 @name="primary">

参考リンク

1
0
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
1
0