Ruby on rails RubyonRails:如何为postgresql编辑database.yml?
Rails新应用程序 当前的database.yml如下所示:Ruby on rails RubyonRails:如何为postgresql编辑database.yml?,ruby-on-rails,ruby,database,ruby-on-rails-3,postgresql,Ruby On Rails,Ruby,Database,Ruby On Rails 3,Postgresql,Rails新应用程序 当前的database.yml如下所示: # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Wa
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
我需要为postgresql数据库编辑这个
我该怎么做?简单地说:
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
host: localhost
来源:正如扎巴所说
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
正如报告中提到的。但是,您可能需要另外一条min\u消息:WARNING
,以便删除。因此,我的database.yml
条目如下所示
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
min_messages: WARNING
您可能对使用postgres默认值生成新应用程序感兴趣:
rails new myapp --database=postgresql
正如这里提到的:只需使用
rails new app_name --database=postgresql
或者如果现有应用程序尝试
development:
adapter: postgresql
encoding: unicode
database: app_dev
pool: 5
username: username
password: password
host: localhost
另一种方法是在&default中使用公共值,然后在其他环境中使用单独的值,这些值可以基于环境变量:
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'] %>
default:&default
适配器:postgresql
编码:unicode
端口:
游泳池:
用户名:
密码:
主持人:
发展:
development:
adapter: postgresql
encoding: unicode
database: app_dev
pool: 5
username: username
password: password
host: localhost
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'] %>