Heroku,Rails 7 CI测试管道,数据库错误

sshcrbum  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(108)

我正在尝试让Heroku Pipeline与我的Rails 7应用程序一起工作。当前遇到与数据库连接/创建相关的问题。在管道测试选项卡中,所有测试都失败,我得到以下错误:

Running 245 tests in parallel using 4 processes
We could not find your database: postgres. Which can be found in the database  configuration file located at config/database.yml.
To resolve this issue:
- Did you create the database for this app, or delete it? You may need to create   your database.
- Has the database name changed? Check your database.yml config has the correct   database name.
To create your database, run:
    bin/rails db:create
Couldn't create 'd7cd1vu5hke8mq-0' database. Please check your configuration.

[...]

DRb::DRbRemoteError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.
To resolve this issue:
- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.
To create your database, run:
    bin/rails db:create
(ActiveRecord::NoDatabaseError)

我对Heroku CI和Pipelines总体来说是相当陌生的。我的config/database.yml文件看起来像这样:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: postgres
  password: <%= ENV['WS_DATABASE_PASSWORD'] %>
  port: 5432

development:
  <<: *default
  database: db/development

# 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:
  <<: *default
  database: db/test

production:
  <<: *default
  database: db/production

我的生产数据库工作正常,但在Heroku上运行测试时出现错误。
我还创建了一个app.json文件,但这也没有帮助:

{
  "environments": {
    "test": {
      "addons":[
        "heroku-postgresql:mini",
        "heroku-redis:mini"
      ]
    }
  }
}

关于为什么我的数据库连接和测试套件不能正常运行有什么想法吗?

okxuctiv

okxuctiv1#

删除database.yml中的userpasswordport设置,这里有一个可靠的文档解释whyRails Database Connection Behavior

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

使用heroku-postgresql:in-dyno插件在app.json中进行postgres测试,如下所述:Heroku CI In-Dyno Databases .你会希望你的Redis测试环境也是这样。

{
  "environments": {
    "test": {
      "addons":[
        "heroku-postgresql:in-dyno",
        "heroku-redis:in-dyno"
      ]
    }
  }
}

相关问题