0
0

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.

Rails database.ymlの記載内容の適用のされ方に関するメモ

Last updated at Posted at 2020-12-08

記事の目的

データベースの接続の設定ファイルであるdatabase.ymlの記載内容の適用のされ方に関するメモ

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV["DB_USERNAME"] %>
  password: <%= ENV["DB_PASSWORD"] %>
  host: localhost

development:
  <<: *default
  database: book_action_development


test:
  <<: *default
  database: book_action_test


production:
  <<: *default
  database: book_action_production
  username: root
  password: <%= Rails.application.credentials.db[:password] %>
  host: <%= Rails.application.credentials.db[:hostname] %>

勘違い

あるエラーが起きて、
default部分に記載のusername: <%= ENV["DB_USERNAME"] %>と
productionに記載のusername: root
が競合してしまうと思っていた。

実際

競合はせず、productionに記載のusername: rootが優先されるそう。

まとめ

なぜそうなるかは詳しく調べられていないので、今後調べる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?