Ruby on Rails: How can i edit database.yml for postgresql?

前端 未结 7 1210
我寻月下人不归
我寻月下人不归 2020-12-08 06:26

rails new app=>

The current database.yml is like that=>

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your         


        
7条回答
  •  自闭症患者
    2020-12-08 06:57

    Another way is to have the common values in &default and then have individual values for the other environments, which can be based on environment variables:

    default: &default
      adapter:  postgresql
      encoding: unicode
      port:     <%= ENV.fetch("POSTGRESQL_PORT", "5432") %>
      pool:     <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      username: <%= ENV['POSTGRESQL_USER_NAME'] %>
      password: <%= ENV.fetch("POSTGRESQL_PASSWORD", "myS3cr3tP4ssw0rd") %>
      host:     <%= ENV['POSTGRESQL_HOST'] %>
    
    development:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>-development
      host: db
    
    test:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>-test
      host: db
    
    production:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>
    

    Here all the values can come from environment variables (if you use Docker or Bitbucket Pipelines) or you can have them in your .env files.

提交回复
热议问题