aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
|
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-3/+8
| | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* Fix the MySQL column type `SET` registration bugTaishi Kasuga2015-06-201-0/+4
|
* Map :bigint as NUMBER(19) sql_type by using `:limit => 19` for OracleYasuo Honda2015-06-011-1/+5
| | | | | | | | | | | | | | | | | | | since NUMBER(8) is not enough to store the maximum number of bigint. Oracle NUMBER(p,0) as handled as integer because there is no dedicated integer sql data type exist in Oracle database. Also NUMBER(p,s) precision can take up to 38. p means the number of digits, not the byte length. bigint type needs 19 digits as follows. $ irb 2.2.2 :001 > limit = 8 => 8 2.2.2 :002 > maxvalue_of_bigint = 1 << ( limit * 8 - 1) => 9223372036854775808 2.2.2 :003 > puts maxvalue_of_bigint.to_s.length 19 => nil 2.2.2 :004 >
* Add schema cache to new connection pool after forkEugene Kenny2015-05-171-0/+46
| | | | | | | | | | | | | | Active Record detects when the process has forked and automatically creates a new connection pool to avoid sharing file descriptors. If the existing connection pool had a schema cache associated with it, the new pool should copy it to avoid unnecessarily querying the database for its schema. The code to detect that the process has forked is in ConnectionHandler, but the existing test for it was in the ConnectionManagement test file. I moved it to the right place while I was writing the new test for this change.
* AR::ConPool - establish connections outside of critical section.thedarkone2015-05-141-1/+1
|
* AR::ConPool - reduce post checkout critical section.thedarkone2015-05-141-1/+3
| | | | Move post checkout connection verification out of mutex.synchronize.
* Revert "Merge pull request #19404 from dmathieu/remove_rack_env"Jeremy Kemper2015-03-201-0/+34
| | | | | | | 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-34/+0
|
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-1/+1
|
* Properly lookup the limit for bigintSean Griffin2015-02-021-0/+5
| | | | Fixes #18787.
* Remove deprecated access to connection specification using a string acessor.Rafael Mendonça França2015-01-041-38/+0
| | | | Now all strings will be handled as a URL.
* Return an array of pools from `connection_pools`Rafael Mendonça França2015-01-041-3/+1
|
* Merge pull request #17305 from ↵Rafael Mendonça França2014-10-311-0/+89
|\ | | | | | | | | ziggythehamster/activerecord-connectionhandling-RAILS_ENV-without-rails If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"] in ActiveRecord::ConnectionHandling
| * If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"].Keith Gable2014-10-211-0/+89
| | | | | | | | | | | | | | 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.
* | fix MySQL enum type lookup with values matching another type. Closes #17402.Yves Senn2014-10-291-0/+4
|/ | | | | | | | | | The MySQLAdapter type map used the lowest priority for enum types. This was the result of a recent refactoring and lead to some broken lookups for enums with values that match other types. Like `8bit`. This patch restores the priority to what we had before the refactoring. /cc @sgrif
* Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-2/+2
| | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* Parsing DATABASE_URI, use URI#hostname: it's smarter about IPv6Matthew Draper2014-06-141-0/+12
| | | | Fixes #15705.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Move types to the top level `ActiveRecord` namespaceSean Griffin2014-05-271-142/+0
| | | | | `ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`
* Add test case for clear mappingsAkshay Vishnoi2014-05-281-0/+10
|
* Remove special case in schema dumper for decimal without scaleSean Griffin2014-05-231-6/+10
|
* Allow additional arguments to be used during type map lookupsSean Griffin2014-05-221-0/+17
| | | | | | | | Determining things like precision and scale in postgresql will require the given blocks to take additional arguments besides the OID. - Adds the ability to handle additional arguments to `TypeMap` - Passes the column type to blocks when looking up PG types
* Use the generic type map object for mysql field lookupsSean Griffin2014-05-201-0/+13
|
* Remove :timestamp column typeSean Griffin2014-05-192-7/+4
| | | | | | | | | | | | The `:timestamp` type for columns is unused. All database adapters treat them as the same database type. All code in `ActiveRecord` which changes its behavior based on the column's type acts the same in both cases. However, when the type is passed to code that checks for the `:datetime` type, but not `:timestamp` (such as XML serialization), the result is unexpected behavior. Existing schema definitions will continue to work, and the `timestamp` type is transparently aliased to `datetime`.
* Delegate `Column#type` to the injected type objectSean Griffin2014-05-193-0/+263
| | | | | | | | | | | | | | | | The decision to wrap type registrations in a proc was made for two reasons. 1. Some cases need to make an additional decision based on the type (e.g. a `Decimal` with a 0 scale) 2. Aliased types are automatically updated if they type they point to is updated later. If a user or another adapter decides to change the object used for `decimal` columns, `numeric`, and `number` will automatically point to the new type, without having to track what types are aliased explicitly. Everything else here should be pretty straightforward. PostgreSQL ranges had to change slightly, since the `simplified_type` method is gone.
* Rearrange deck chairs on the titanic. Organize connection handling test cases.Jeremy Kemper2014-04-214-249/+246
|
* 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