aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_handling.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove legacy mysql adapterRyuta Kamizono2015-12-211-1/+1
| | | | Follow up to #22642.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-3/+3
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Improve readability of docs by using code tag [ci skip]Prakash Laxkar2015-09-291-1/+1
|
* AR::ConPool - remove synchronization around connection cache.thedarkone2015-05-141-1/+1
| | | | | | | | | | | | | | | | | | | | Renamed `@reserved_connections` -> `@thread_cached_conns`. New name clearly conveys the purpose of the cache, which is to speed-up `#connection` method. The new `@thread_cached_conns` now also uses `Thread` objects as keys (instead of previously `Thread.current.object_id`). Since there is no longer any synchronization around `@thread_cached_conns`, `disconnect!` and `clear_reloadable_connections!` methods now pre-emptively obtain ownership (via `checkout`) of all existing connections, before modifying internal data structures. A private method `release` has been renamed `thread_conn_uncache` to clear-up its purpose. Fixed some brittle `thread.status == "sleep"` tests (threads can go into sleep even without locks).
* Revert "Merge pull request #19404 from dmathieu/remove_rack_env"Jeremy Kemper2015-03-201-1/+1
| | | | | | | Preserving RACK_ENV behavior. This reverts commit 7bdc7635b885e473f6a577264fd8efad1c02174f, reversing changes made to 45786be516e13d55a1fca9a4abaddd5781209103.
* don't fallback to RACK_ENV when RAILS_ENV is not presentDamien Mathieu2015-03-191-1/+1
|
* Spell PostgreSQL correctly :elephant:Akira Matsuda2015-02-281-1/+1
| | | | [ci skip]
* Check for Rails.env instead of RailsPavel Penkov2014-12-251-1/+1
| | | | | `Rails` constant is added by rails-html-sanitizer leading to bugs in non-Rails apps using ActiveRecord and ActionMailer
* If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"].Keith Gable2014-10-211-1/+1
| | | | | | | This fixes a regression introduced by 6cc03675d30b58e28f585720dad14e947a57ff5b. ActiveRecord, if used without Rails, always checks the "default_env" environment. This would be OK, except that Sinatra also supports environments, and it runs with {RACK|RAILS}_ENV=production. This patch adds a fallback to RAILS_ENV and RACK_ENV (and ultimately default_env) if Rails.env doesn't exist.
* Don't deprecate after allMatthew Draper2014-04-091-16/+2
|
* Less ambition, more deprecationMatthew Draper2014-04-091-16/+16
| | | | | | | | The "DATABASE_URL_*" idea was moving in the wrong direction. Instead, let's deprecate the situation where we end up using ENV['DATABASE_URL'] at all: the Right Way is to explicitly include it in database.yml with ERB.
* Rearrange the config merger some moreMatthew Draper2014-04-081-19/+16
| | | | | | | This seems to simplify the operative part. Most importantly, by pre-loading all the configs supplied in ENV, we ensure the list is complete: if the developer specifies an unknown config, the exception includes a list of valid ones.
* 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.