On Sun, Jul 22, 2012 at 12:52:26PM -0400, TuteC wrote: > On Tue, Jul 17, 2012 at 2:27 PM, Aaron Patterson > <[email protected]> wrote: > > If you find entry points where the environment variable *isn't* used, > > then we should consider it a bug. For example, I just discovered that > > `rake db:schema:dump` will not use the environment variable: > > > > https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake#L229 > > > > So someone should send a patch for that. :-) > > Is it simple as: > > - ActiveRecord::Base.establish_connection(Rails.env) > + ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"] > || Rails.env) > > wherever I see it not being used?
Yes, but I think it would be better if we change the definition of
`establish_connection` in connection_handling.rb. Like this:
diff --git a/activerecord/lib/active_record/connection_handling.rb
b/activerecord/lib/active_record/connection_handling.rb
index bda41df..ce1f84f 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -36,7 +36,7 @@ module ActiveRecord
#
# The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError
# may be returned on an error.
- def establish_connection(spec = ENV["DATABASE_URL"])
+ def establish_connection(spec = ENV["DATABASE_URL"] || Rails.env)
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new
spec, configurations
spec = resolver.spec
Then we should just call `establish_connection` and it will
automatically choose the right thing. (Note that this diff may break
stuff, I haven't run the tests to find out ;-) )
> Also inside namespace :test?
Yes.
> Are there tests for rake tasks?
There should be tests in Railties.
--
Aaron Patterson
http://tenderlovemaking.com/
pgpsTjNQQLSnW.pgp
Description: PGP signature
