aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_handling.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* entry is always a HashRafael Mendonça França2014-04-081-1/+1
|
* Check env_url only onceRafael Mendonça França2014-04-081-2/+7
|
* Only call DEFAULT_ENV proc one timeRafael Mendonça França2014-04-081-2/+5
|
* Make sure DEFAULT_URL only override current environment databaseRafael Mendonça França2014-04-081-1/+1
| | | | configuration
* Only apply DATABASE_URL for Rails.envMatthew Draper2014-04-081-28/+14
| | | | | As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure use cases.
* Use Sqlite3 adapter in examplesJulian Simioni2014-03-121-2/+2
| | | | | | | | | | | | | | | | Two bits of example code use sqlite as an adapter, which doesn't exist. Using the code verbatim will raise a LoadError exception: ActiveRecord::Base.establish_connection( "adapter" => "sqlite", "database" => "db.sqlite" ) # => LoadError: Could not load 'active_record/connection_adapters/sqlite_adapter'... Considering this is code a lot of people new to Rails might be running, it's especially confusing. Closes #14367 [ci skip]
* Handle missing environment from non empty configschneems2014-02-211-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If using a `DATABASE_URL` and a `database.yml`. The connection information in `DATABASE_URL` should be merged into whatever environment we are in. As released in 4.1.0rc1 if someone has a database.yml but is missing a key like production: ```yml development: host: localhost ``` Then the check for blank config will return false so the information from the `DATABASE_URL` will not be used when attempting to connect to the `production` database and the connection will incorrectly fail. This commit fixes this problem and adds a test for the behavior. In addition the ability to specify a connection url in a `database.yml` like this: ``` production: postgres://localhost/foo ``` Was introduced in 4.1.0rc1 though should not be used, instead using a url sub key ``` production: url: postgres://localhost/foo ``` This url sub key was also introduced in 4.1.0rc1 though the `production: postgres://localhost/foo` was not removed. As a result we should not test this behavior.
* Ensure Active Record connection consistencyschneems2014-01-091-3/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored. There are many ways that active record initiates a connection today: - Stand Alone (without rails) - `rake db:<tasks>` - ActiveRecord.establish_connection - With Rails - `rake db:<tasks>` - `rails <server> | <console>` - `rails dbconsole` We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used. Here is my prosed matrix of how this behavior should work: ``` No database.yml No DATABASE_URL => Error ``` ``` database.yml present No DATABASE_URL => Use database.yml configuration ``` ``` No database.yml DATABASE_URL present => use DATABASE_URL configuration ``` ``` database.yml present DATABASE_URL present => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url` sub key "wins". If other paramaters `adapter` or `database` are specified in YAML, they are discarded as the `url` sub key "wins". ``` ### Implementation Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`. To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
* Deprecate use of string in establish_connection as connection lookupJosé Valim2013-12-241-0/+7
|
* Only build a ConnectionSpecification if requiredJosé Valim2013-12-241-1/+1
|
* Guarantee the connection resolver handles string valuesJosé Valim2013-12-231-2/+2
| | | | | | | | | This commit also cleans up the rake tasks that were checking for DATABASE_URL in different places. In fact, it would be nice to deprecate DATABASE_URL usage in the long term, considering the direction we are moving of allowing those in .yml files.
* removes calls to AR::Runtime.instanceXavier Noria2013-04-131-2/+2
| | | | | | | | | | Registries have class-level accessors to write clean code, let's use them. This makes style uniform also with existing usage in ScopeRegistry and InstrumentationRegistry. If performance of the method_missing callback was ever considered to be a concern, then we should stop using it altogether and probably remove the callback. But while we have the feature we should use it.
* Created a runtime registry for thread local variables in active record.wangjohn2013-04-091-2/+2
|
* nodoc AR::ConnectionHandling for adapters [ci skip]Francesco Rodriguez2013-03-151-5/+5
|
* 1.9 hash syntax changesAvnerCohen2012-11-081-8/+8
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-1/+0
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* Make connection pool retrieval fasterJon Leighton2012-08-311-1/+1
| | | | | | * Loop rather than recurse in retrieve_connection_pool * Key the hash by class rather than class name. This avoids creating unnecessary strings.
* load active_support/core_ext/module/delegation in active_support/railsXavier Noria2012-08-021-1/+0
|
* Simplify AR configuration code.Jon Leighton2012-06-151-0/+4
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* removes verify_active_connections!Xavier Noria2012-02-241-1/+1
| | | | | | | The method verify_active_connections! was used in the old days (up to 2.1 I think) by the dispatcher to verify the connections, but nowadays we do that in a different way and this method is obsolete.
* Delegate clear_active_connections to handler as wellCarlos Antonio da Silva2012-01-141-6/+2
|
* Support establishing connection on ActiveRecord::Model.Jon Leighton2011-12-281-0/+100
This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.