【问题标题】:URI::InvalidURIError: bad URI(is not URI?) when deploying HEROKU app with multiple databasesURI::InvalidURIError: bad URI(is not URI?) when deploying HEROKU app with multiple databases
【发布时间】:2019-03-13 01:54:00
【问题描述】:

我正在尝试部署一个带有多个数据库的 heroku 应用程序(目前为 2 个)。我正在学习本教程

Multiple database guide

说我需要像这样配置一个文件

production:
  adapter: postgresql
  encoding: utf8
  url:  <%= ENV["DATABASE_DAVILA_URL"] %>
  pool: <%= ENV["DB_POOL"] || 5 %>

问题是当我尝试部署到 Heroku 时,会发生此错误

-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       URI::InvalidURIError: bad URI(is not URI?): <%= ENV["DATABASE_DAVILA_URL"] %>

这就像没有正确解析链接,因为我什至尝试硬编码变量中的 URI 并且没有工作。这是 env vars 的重要部分:

DATABASE_DAVILA_URL:         postgres://somethinguser:somethingpass@somethinghost.compute-1.amazonaws.com:5432/somethingdb
DATABASE_URL:                postgres://somethinguser:somethingpass@somethinghost.compute-1.amazonaws.com:5432/somethingdb
HEROKU_POSTGRESQL_MAUVE_URL: postgres://somethinguser:somethingpass@somethinghost.compute-1.amazonaws.com:5432/somethingdb

我几乎遵循了我找到的所有教程,但我不断收到同样的错误。我什至用这段代码尝试了我读到的“不在预编译阶段加载环境变量”之类的东西,但没有改变任何东西

module Indicadoresrails
  class Application < Rails::Application

    config.load_defaults 5.2

    config.assets.initialize_on_precompile = false
  end
end

请帮忙:(

【问题讨论】:

  • 您是否运行了heroku config:set 命令来设置这些环境变量?
  • 是的,我做到了。之后我得到了我发布的环境变量值
  • 您可能想要更改这些凭据:-O
  • 数据库 URL 是您真正的生产配置设置吗?如果是这种情况,您应该立即更改密码。如果该数据库中已有数据,您可能需要通知您的数据保护官。
  • 那些只是虚拟数据,旧数据库的副本,没什么重要的。

标签: ruby-on-rails ruby postgresql heroku multiple-databases


【解决方案1】:

确保URI.parse(&lt;DATABASE_DAVILA_URL here&gt;) 成功。您的数据库用户名/密码中可能有非 url 安全字符。你需要URI.encode他们。

【讨论】:

  • 我已经在 ruby​​ 控制台中尝试过这个:uri = URI.parse(&lt;URI&gt;) uri.user uri.password 等等它们都可以工作
猜你喜欢
  • 2017-12-18
  • 1970-01-01
  • 2020-06-11
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 2018-06-12
  • 2012-02-23
  • 2011-07-19
相关资源
最近更新 更多