I'm trying to get Heroku Pipeline working with my Rails 7 application. Currently running into problems related to database connection / creation. In the pipeline test tab all tests fails and I get the following error:
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)
I'm quite new to Heroku CI and Pipelines overall. My config/database.yml
file looks like this:
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
My production database works fine, but the errors occurs when running tests on Heroku.
I've also created a app.json
file, but this didn't help either:
{
"environments": {
"test": {
"addons":[
"heroku-postgresql:mini",
"heroku-redis:mini"
]
}
}
}
Any ideas on why my database connection and test suite won't run properly?
Remove user
, password
, and port
settings in database.yml
there is a solid doc explaining why
here: Rails Database Connection Behavior
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
And use heroku-postgresql:in-dyno
addon for postgres tests in app.json
as described here: Heroku CI In-Dyno Databases. You'll want the same for your Redis test env.
{
"environments": {
"test": {
"addons":[
"heroku-postgresql:in-dyno",
"heroku-redis:in-dyno"
]
}
}
}