Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database configurations building when DATABASE_URL present #35244

Merged

Conversation

palkan
Copy link
Contributor

@palkan palkan commented Feb 12, 2019

Summary

Rails Version: 6.0.0.beta1

Having the following database.yml:

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

development:
  <<: *default
  database: project_development

test:
  <<: *default
  database: project_test

production:
  <<: *default
  database: project_production

I got the following exceptions running tests (after calling maintain_test_schema!):

PG::ConnectionBad:
#   FATAL:  database "project_development" does not exist
#   /bundle/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'

After some investigation I found that DB configurations all had "test" as env_name.
And specifically for test env:

[6] pry(main)> resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
=> #<ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver:0x000055b27e697590
 @configurations=
  #<ActiveRecord::DatabaseConfigurations:0x000055b27e5febb0
   @configurations=
    [#<ActiveRecord::DatabaseConfigurations::UrlConfig:0x000055b27bec2830
      @config=
       {"adapter"=>"postgresql",
        "encoding"=>"unicode",
        "pool"=>5,
        "database"=>"project_development",
        "username"=>"postgres",
        "password"=>"postgres",
[7] pry(main)> resolver.resolve(:test, :test)
=> {"adapter"=>"postgresql",
 "encoding"=>"unicode",
 "pool"=>5,
 "database"=>"project_development",
 "username"=>"postgres",
 "password"=>"postgres",
 "port"=>5432,
 "host"=>"postgres",
 "name"=>"test"}

This is a regression comparing to 5.2.

NOTE: For those struggling with this problem: it could be fixed by adding url

default: &default
  url: <%= ENV['DATABASE_URL'] %>

@eileencodes eileencodes merged commit be099cc into rails:master Feb 13, 2019
@eileencodes eileencodes added this to the 6.0.0 milestone Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants