aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_handling.rb
Commit message (Collapse)AuthorAgeFilesLines
* Flush idle database connectionsMatthew Draper2017-11-261-1/+1
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* `DEFAULT_ENV` falls back to `default_env` when `RAILS_ENV` or `RACK_ENV` is ↵Ryuta Kamizono2017-05-251-1/+1
| | | | | | an empty string Follow up of #27399.
* fixes remaining RuboCop issues [Vipul A M, Xavier Noria]Xavier Noria2016-09-011-1/+1
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Remove unused `ActiveRecord::Base.connection_id`Sean Griffin2016-06-291-8/+0
| | | | | | | | This method appears to have been partially used in connection pool caching, but it was introduced without much reasoning or any tests. One edge case test was added later on, but it was focused on implementation details. This method is no longer used outside of tests, and as such is removed.
* [ci skip] fix typo in ActiveRecord::ConnectionHandlingAlex Kitchens2016-06-201-1/+1
|
* Remove `name` from `establish_connection`Arthur Neves2016-05-241-1/+6
| | | | | Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification.
* Move establish_connection to handlerArthur Neves2016-05-241-13/+5
|
* remove_connection should not remove parent connectionArthur Neves2016-05-111-1/+2
| | | | | | When calling remove_connection in a subclass, that should not fallback to the parent, otherwise it will remove the parent connection from the handler.
* Merge pull request #24971 from arthurnn/arthurnn/dont_cache_specification_nameArthur Nogueira Neves2016-05-111-1/+1
|\ | | | | Dont cache the conn_spec_name when empty
| * Dont cache the conn_spec_name when emptyArthur Neves2016-05-111-1/+1
| | | | | | | | | | | | | | | | We cannot cache the connection_specification_name when it doesnt exist. Thats because the parent value could change, and we should keep failling back to the parent. If we cache that in a children as an ivar, we would not fallback anymore in the next call, so the children would not get the new parent spec_name.
* | Set conn_spec_name after removeArthur Neves2016-05-111-2/+2
|/ | | | | | `remove_connection` can reset the `connection_specification_name`, so we need to to set it after the remove_connection call on `establish_connection` method.
* Make sure we reset the connection_specification_name onArthur Neves2016-05-101-1/+8
| | | | | | | | | | | | | | remove_connection When calling `remove_connection` on a model, we delete the pool so we also need to reset the `connection_specification_name` so it will fallback to the parent. This was the current behavior before rails 5, which will fallback to the parent connection pool. [fixes #24959] Special thanks to @jrafanie for working with me on this fix.
* Followup to #24844Jon Moss2016-05-071-3/+2
| | | | | | | Some slight documentation edits and fixes. Also, run remove unnecessary `RuntimeError`. r? @arthurnn
* s/specification_name/connection_specification_nameArthur Neves2016-05-061-10/+10
|
* s/specification_id/specification_nameArthur Neves2016-05-051-11/+11
|
* Better code readabilityArthur Neves2016-05-051-3/+1
|
* Better specification_id methodArthur Neves2016-05-051-10/+7
|
* Rename methodArthur Neves2016-05-051-3/+3
|
* Refactor connection handlerArthur Neves2016-05-051-7/+27
| | | | | | | | | | | | | | | ConnectionHandler will not have any knowlodge of AR models now, it will only know about the specs. Like that we can decouple the two, and allow the same model to use more than one connection. Historically, folks used to create abstract AR classes on the fly in order to have multiple connections for the same model, and override the connection methods. With this, now we can override the `specificiation_id` method in the model, to return a key, that will be used to find the connection_pool from the handler.
* 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
|