我想通过 Dokku
部署我的应用程序到 VPS。
将 dokku-postgres
放在一起documentation以及关于此事的相关稀缺互联网文档(GitHub 上的 one),似乎有必要配置 database.yml
使用 url 环境变量 url: <%= ENV['DATABASE_URL'] %>
由于找不到任何其他信息来源,我想知道如何database.yml
应该进行配置,Rails 如何连接到使用 Dokku 创建的 postgres 服务。
例如,理所当然地认为链接url
到 DATABASE_URL
变量是必需的,这足以在我的 Rails 应用程序和 postgres 服务之间建立连接,还是仍然需要使用用户名和密码?在后一种情况下,我应该使用什么用户名和密码?
下面是目前我的database.yml
好像。
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: asarluhi
development:
<<: *default
database: fireworks_app_development
test:
<<: *default
database: fireworks_app_test
production:
<<: *default
database: fireworks_app_production
pool: 25
username: fireworks_app
password: <%= ENV['FIREWORKS_APP_DATABASE_PASSWORD'] %>
这个文件是在我创建应用程序时按原样创建的(除了用于生产的更大的池大小)。您建议如何编辑 production
部分?
dokku-postgres 文档指出,默认情况下将在链接的应用程序上设置以下内容(除此之外别无其他):
DATABASE_URL=postgres://postgres:SOME_PASSWORD@dokku-postgres-lolipop:5432/lolipop
我将使用 fireworks_app_production
代替 Lollipop postgres 服务示例以匹配 database.yml
中的数据库名称
指向url
后,用户名 和密码 是否仍然必要?到 DATABASE_URL
多变的?我需要添加或删除其他任何内容吗?
最佳答案
你不用担心dokku的database.yml,只需要将你的应用上传到服务器,让我们使用“fireworks”作为这个例子的名称。
当您第一次上传该应用时,它会自动创建,因此您无需创建。
然后你安装postgres插件并运行
# that will create the container for the database
$ dokku postgres:create fireworks
# and then you link both, the app with the database
$ dokku postgres:link fireworks fireworks
你不用担心其他任何事情,dokku 会连接这个
然后您只需运行 db:migrate
一切就绪!
关于ruby-on-rails - 如何为生产配置 database.yml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43590647/