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

Rails RC2 regression in multiple datbases #36736

Closed
morgoth opened this issue Jul 23, 2019 · 6 comments

Comments

@morgoth
Copy link
Member

commented Jul 23, 2019

This commit f2ad69f inlcuded in Rails RC2 caused a regression in case where multiple database are used and DATABASE_URL environment variable is set.

Reproduction of the bug is here https://github.com/morgoth/mdbug (details in commit morgoth/mdbug@048db24) and can be seen by running DATABASE_URL="sqlite3:db/development.sqlite3" bin/rails r "Dog.count" which throws an error:

The `animals` database is not configured for the `development` environment. (ActiveRecord::AdapterNotSpecified)

Available databases configurations are:

default
development
test

When running bin/rails r "Dog.count" all is working fine.
It doesn't matter if DATABASE_URL env is used in the config file or not, it's only the fact that is set as env variable.

/cc @eileencodes

@eileencodes eileencodes self-assigned this Jul 23, 2019

@rafaelfranca rafaelfranca added this to the 6.0.0 milestone Jul 23, 2019

@eileencodes

This comment has been minimized.

Copy link
Member

commented Jul 23, 2019

Thanks @morgoth! Working on a fix.

seejohnrun added a commit to seejohnrun/rails that referenced this issue Jul 24, 2019

Fix multiple database support for DATABASE_URL env variable
This commit fixes an issue where multi-database configurations were
incompatible with setting a `DATABASE_URL` environment variable.

As part of this work, this commit also includes a light refactor
to make both multi and single database configurations lead into the same
code path so they behave the same.

As mentioned in rails#36736, this regression was introduced as part of
f2ad69f
@saslani

This comment has been minimized.

Copy link

commented Aug 3, 2019

@eileencodes still not working. I have multiple databases. None are replicas:
Before rails 6, I used multiverse gem and everything looked fine.
rails: gem "rails", "6.0.0.rc2"

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
  establish_connection :primary
end

.

class ObsRecord < ActiveRecord::Base
  self.abstract_class = true
  establish_connection :obs
end

.

class AbcRecord < ActiveRecord::Base
  self.abstract_class = true
  establish_connection :abc
end

database.yml

staging:
  primary:
    <<: *default
    adapter: postgresql
    url:  <%= ENV['DATABASE_URL'] %>
    username: <%= ENV['DATABASE_USER'] %>
    password: <%= ENV['DATABASE_PASSWORD'] %>
  obs:
    <<: *default
    adapter: postgresql
    url: <%= ENV['OBS_DATABASE_URL'] %> # this would be the name heroku postgres provides 
    username: <%= ENV['OBS_DATABASE_USER'] %>
    password: <%= ENV['OBS_DATABASE_PASSWORD'] %>
    migrations_paths: db/obs_migrate
  abc:
    <<: *default
    adapter: postgresql
    url: <%= ENV['ABC_DATABASE_URL'] %>
    username: <%= ENV['ABC_DATABASE_USER'] %>
    password: <%= ENV['ABC_DATABASE_PASSWORD'] %>
    migrations_paths: db/abc_migrate

Heroku error:

/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:251:in `resolve_symbol_connection': The `abc` database is not configured for the `staging` environment. (ActiveRecord::AdapterNotSpecified)

Available databases configurations are:

default
prod_uat_default
development
test
staging
uat
production
@morgoth

This comment has been minimized.

Copy link
Member Author

commented Aug 3, 2019

@saslani This fix is not yet released - did you try 6-0-stable branch?

@isantoshsingh

This comment has been minimized.

Copy link

commented Aug 3, 2019

Hey @morgoth
I am too facing this issue while deploying to heroku.
any workaround?

@wjessop

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

@isantoshsingh Did you try 6-0-stable?

@isantoshsingh

This comment has been minimized.

Copy link

commented Aug 5, 2019

@wjessop yes and issue solved after adding below code in my gemfile
Gemfile
gem 'rails', :git => 'https://github.com/rails/rails.git', :branch => '6-0-stable'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.