diff options
author | Jeremy Baker <jhubert@gmail.com> | 2016-02-04 01:32:45 -0800 |
---|---|---|
committer | Jeremy Baker <jhubert@gmail.com> | 2016-02-04 01:32:45 -0800 |
commit | 7429bc58a0dffa94636b21cc0cba1d19a5ae7a84 (patch) | |
tree | 57538ab8a1d933950d20d6f78343bbf5795be129 /activerecord | |
parent | dfa48f200cbc5c1ca18457a8cde14642e12af594 (diff) | |
download | rails-7429bc58a0dffa94636b21cc0cba1d19a5ae7a84.tar.gz rails-7429bc58a0dffa94636b21cc0cba1d19a5ae7a84.tar.bz2 rails-7429bc58a0dffa94636b21cc0cba1d19a5ae7a84.zip |
Remove the assumption of schema in DATABASE_URL
If you set the DATABASE_URL environment variable to `mydatabase` by accident, you end up getting a series of errors that are hard to trace. For example:
```
warning: already initialized constant ActiveRecord::Base::OrmAdapter
```
Turns out the cascade of errors is due to the error raised by `.tr` being called on `nil`.
This commit makes sure that `scheme` is set before calling `.tr` on it. My previous iteration used `@uri.scheme.try(:tr, '-', '_')` but using the `&&` logical operator is a fair bit faster: http://stackoverflow.com/questions/26655032/try-vs-performance
With this change, the error message becomes much more understandable:
```
FATAL: database "mydatabase" does not exist (ActiveRecord::NoDatabaseError)
```
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index f633892dee..4bc6447368 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -33,7 +33,7 @@ module ActiveRecord def initialize(url) raise "Database URL cannot be empty" if url.blank? @uri = uri_parser.parse(url) - @adapter = @uri.scheme.tr('-', '_') + @adapter = @uri.scheme && @uri.scheme.tr('-', '_') @adapter = "postgresql" if @adapter == "postgres" if @uri.opaque |