aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Drop in @jeremy's new database.yml template textMatthew Draper2014-04-091-0/+8
| | | | | In passing, allow multi-word adapters to be referenced in a URL: underscored_name must become hyphened-name.
* Don't deprecate after allMatthew Draper2014-04-091-11/+9
|
* Less ambition, more deprecationMatthew Draper2014-04-091-59/+11
| | | | | | | | 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.
* Ensure we correctly and immediately load all ENV entriesMatthew Draper2014-04-081-0/+21
| | | | .. even when the supplied config made no hint that name was relevant.
* Give a deprecation message even when the lookup failsMatthew Draper2014-04-081-2/+4
| | | | | | | | | | | | If the supplied string doesn't contain a colon, it clearly cannot be a database URL. They must have intended to do a key lookup, so even though it failed, give the explanatory deprecation warning, and raise the exception that lists the known configs. Conveniently, this also simplifies our logical behaviour: if the string matches a known configuration, or doesn't contain a colon (and is therefore clearly not a URL), then we output a deprecation warning, and behave exactly as we would if it were a symbol.
* Test DATABASE_URL has precendance over DATABASE_URL_#{environment}Rafael Mendonça França2014-04-081-0/+9
|
* Make sure DEFAULT_URL only override current environment databaseRafael Mendonça França2014-04-081-9/+29
| | | | configuration
* Only apply DATABASE_URL for Rails.envMatthew Draper2014-04-081-17/+26
| | | | | As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure use cases.
* Avoid a spurious deprecation warning for database URLsMatthew Draper2014-04-031-0/+48
| | | | | | | | | | | | | | | | | | This is all about the case where we have a `DATABASE_URL`, and we have a `database.yml` present, but the latter doesn't contain the key we're looking for. If the key is a symbol, we'll always connect to `DATABASE_URL`, per the new behaviour in 283a2edec2f8ccdf90fb58025608f02a63948fa0. If the key is a string, on the other hand, it should always be a URL: the ability to specify a name not present in `database.yml` is new in this version of Rails, and that ability does not stretch to the deprecated use of a string in place of a symbol. Uncovered by @guilleiguaran while investigating #14495 -- this actually may be related to the original report, but we don't have enough info to confirm.
* Reap connections based on owning-thread deathMatthew Draper2014-03-181-6/+0
| | | | | | | | | | | | | | | | .. not a general timeout. Now, if a thread checks out a connection then dies, we can immediately recover that connection and re-use it. This should alleviate the pool exhaustion discussed in #12867. More importantly, it entirely avoids the potential issues of the reaper attempting to check whether connections are still active: as long as the owning thread is alive, the connection is its business alone. As a no-op reap is now trivial (only entails checking a thread status per connection), we can also perform one in-line any time we decide to sleep for a connection.
* Merge pull request #14380 from ↵Yves Senn2014-03-151-1/+1
|\ | | | | | | | | tgxworld/use_teardown_helper_method_in_activerecord Use teardown helper method.
| * Use teardown helper method.Guo Xiang Tan2014-03-141-1/+1
| | | | | | | | | | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* | Allow custom JDBC urlsschneems2014-03-141-0/+6
|/ | | | mitigates #14323
* Handle missing environment from non empty configschneems2014-02-211-15/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Restore DATABASE_URL even if it's nil in connection_handler testPrathamesh Sonpatki2014-01-101-1/+1
| | | | | - We have to restore DATABASE_URL to its previous state irrespective of previous value is nil or not
* Ensure Active Record connection consistencyschneems2014-01-091-0/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Move method used only in the test to the test code itselfIvan Kataitsev2013-04-251-0/+9
|
* hide more data in the schema cacheAaron Patterson2013-03-141-13/+10
|
* safely publish columns and columns hash infoAaron Patterson2013-03-141-9/+9
|
* Alias refute methods to assert_not and perfer assert_not on testsRafael Mendonça França2012-12-311-5/+5
|
* Fix memory leak in development modeJon Leighton2012-11-301-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Keying these hashes by klass causes reloadable classes to never get freed. Thanks to @thedarkone for pointing this out in the comments on 221571beb6b4bb7437989bdefaf421f993ab6002. This doesn't seem to make a massive difference to performance. Benchmark --------- require 'active_record' require 'benchmark/ips' class Post < ActiveRecord::Base establish_connection adapter: 'sqlite3', database: ':memory:' end GC.disable Benchmark.ips(20) do |r| r.report { Post.connection } end Before ------ Calculating ------------------------------------- 5632 i/100ms ------------------------------------------------- 218671.0 (±1.9%) i/s - 4364800 in 19.969401s After ----- Calculating ------------------------------------- 8743 i/100ms ------------------------------------------------- 206525.9 (±17.8%) i/s - 4039266 in 19.992590s
* Use "refute" instead of "assert !"Carlos Antonio da Silva2012-11-271-6/+5
| | | | Remove FIXME tag from abstract adapter test.
* Properly deprecate ConnectionHandler#connection_poolsJon Leighton2012-11-091-1/+7
| | | | | | | | Rather than just changing it and hoping for the best. Requested by @jeremy: https://github.com/rails/rails/commit/ba1544d71628abff2777c9c514142d7e9a159111#commitcomment-2106059
* Remove ActiveRecord::ModelJon Leighton2012-10-261-2/+2
| | | | | | | | | | 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.
* rename AR::Model::Tag to AR::Tag - fixes #7714Francesco Rodriguez2012-09-201-2/+2
|
* Cache the connection pool for a given classJon Leighton2012-08-311-0/+2
|
* Make connection pool retrieval fasterJon Leighton2012-08-311-9/+4
| | | | | | * Loop rather than recurse in retrieve_connection_pool * Key the hash by class rather than class name. This avoids creating unnecessary strings.
* Simplify AR configuration code.Jon Leighton2012-06-151-3/+2
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-251-1/+1
| | | | | | | | | | | | | | | The core of this fix is a threadsafe, fair Queue class. It is very similar to Queue in stdlib except that it supports waiting with a timeout. The issue this solves is that if several threads are contending for database connections, an unfair queue makes is possible that a thread will timeout even while other threads successfully acquire and release connections. A fair queue means the thread that has been waiting the longest will get the next available connection. This includes a few test fixes to avoid test ordering issues that cropped up during development of this patch.
* Revert "Merge pull request #6416 from pmahoney/threadsafe-connection-pool"Rafael Mendonça França2012-05-221-1/+1
| | | | | | | | | | | | This reverts commit d2901f0fc4270a765717ad572d559dc49a56b3a8, reversing changes made to 525839fdd8cc34d6d524f204528d5b6f36fe410c. Conflicts: activerecord/test/cases/connection_pool_test.rb Reason: This change broke the build (http://travis-ci.org/#!/rails/rails/builds/1391490) and we don't have any solution until now. I asked the author to try to fix it and open a new pull request.
* Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-201-1/+1
|
* Allow to run `connection_adapters/quoting_test.rb` independentlyPiotr Sarnacki2012-05-091-1/+3
|
* Merge pull request #5362 from zenprogrammer/quoting_bugAaron Patterson2012-05-091-0/+11
|\ | | | | Fixed bug in ActiveRecord that caused classes to be quoted incorrectly
| * Fixed bug in Quoting that caused classes to be quoted incorrectlyRyan Oblak2012-03-091-0/+11
| |
* | Add support schema cache dump and load.kennyj2012-03-011-0/+15
|/
* connection specification will deep copy the configAaron Patterson2011-12-301-0/+12
|
* Support establishing connection on ActiveRecord::Model.Jon Leighton2011-12-281-1/+1
| | | | | This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.
* Extract common logic into a methodJon Leighton2011-12-241-0/+3
|
* Should clear the primary keys cache alsoJon Leighton2011-12-161-1/+5
|
* Don't store defaults in the schema cacheJon Leighton2011-12-161-1/+1
|
* Cache columns at the model level.Jon Leighton2011-12-161-9/+0
| | | | Allows two models to use the same table but have different primary keys.
* AbstractAdapter#close can be called to add the connection back to theAaron Patterson2011-11-291-0/+16
| | | | pool.
* expire will set in_use to falseAaron Patterson2011-11-291-0/+7
|
* last_use is set on connection leaseAaron Patterson2011-11-291-0/+6
|
* Leased connections return false on second leaseAaron Patterson2011-11-291-2/+11
|
* Adapters keep in_use flag when leasedAaron Patterson2011-11-291-0/+16
|
* Fix schema_cache_test.rb for sqlite3_memJon Leighton2011-11-291-6/+0
|
* pools are 1:1 with spec now rather than 1:1 with classAaron Patterson2011-11-281-2/+0
|
* pushing caching and visitors down to the connectionAaron Patterson2011-11-191-0/+55
|
* Merge pull request #2897 from rsutphin/ar31-remove_connectionAaron Patterson2011-09-061-1/+20
| | | | Patch for issue #2820