1

我构建了一个rails应用程序(使用sqllite),我想将它推送到heroku。我知道我必须使用 postgres,所以我必须gem 'pg'在 gemfile 中添加生产用途。但我不知道如何更改 database.yml。

我的 database.yml 看起来应该如何?它目前的样子:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

我应该用这个代替开发吗?

development:
  adapter: postgresql
  encoding: unicode
  database: poets_app_development
  pool: 5
  username: poets_app
  password:

用户名和密码!?我从来没有为 sqlite 设置过,所以它是从哪里来的?

4

2 回答 2

1

the database.yml file is an abstraction around common database configuration for your rails app.

The username and password could be placed in the file but it is not recommended. You might have set up postgres using a tool like homebrew. This set up is DRY and uses environment variables to protect your secrets. Best of luck!

Consider using the following configuration:

defaults: &defaults
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <%= ENV['YOUR_DB_USERNAME'] %> (username if PostgreSQL via Homebrew)
  password: <%= ENV['YOUR_DB_PWD'] %>

development:
 <<: *defaults
 database: postgres_development

test: &test
  <<: *defaults
  database: postgres_test

production:
  <<: *defaults
  database: postgres_production
于 2013-10-11T14:40:27.437 回答
1

用户和密码与 sqlite 无关。这些是 Postgres 服务器的凭据。查看这篇文章以在 Ubuntu 中配置 Postgres(部分:设置 PostgreSQL 用户和密码)。

您还可以将主机添加到您的database.yml

host: <hostname or ip address. eg.: localhost>
于 2013-10-11T14:37:12.303 回答