6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ActiveRecordが接続しているDBの設定情報を確認するコマンド

Last updated at Posted at 2020-07-29

今回のユースケース

DBクライアントツールにDBの設定情報を入力するために、ActiveRecordが接続しているDBの設定情報を一覧で取得したい。

動作環境

  • Rails 6.0.3.2
  • Microsoft SQL Server 2014

手順

  1. rails cでコンソールを起動する
  2. console内でActiveRecord::Base.connection_configを実行する
$ rails c
Loading development environment (Rails 6.0.3.2)
[1] pry(main)> ActiveRecord::Base.connection_config
=> {:adapter=>"sqlserver",
 :encoding=>"utf8",
 :username=>"hoge",
 :password=>"fuga",
 :tds_version=>7.4,
 :host=>"127.0.0.1",
 :database=>"piyo",
 :timeout=>15000,
 :port=>1433}

※デフォルトのdevelopment環境以外の環境でDBの設定情報を確認したい場合は、rails c -e 環境名で環境を指定してコンソールを立ち上げて、console内でActiveRecord::Base.connection_configを実行することで確認が出来る。

$ rails c -e test
Loading test environment (Rails 6.0.3.2)
[1] pry(main)> ActiveRecord::Base.connection_config
=> {:adapter=>"sqlserver",
 :encoding=>"utf8",
 :username=>"hoge",
 :password=>"fuga",
 :tds_version=>7.4,
 :host=>"127.0.0.1",
 :database=>"piyo_test",
 :timeout=>5000}

参照

感想

環境変数で設定している値も一覧で確認できたので便利でした。

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?