| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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)
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 >
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
Move post checkout connection verification out of mutex.synchronize.
|
|
|
|
|
|
|
| |
Preserving RACK_ENV behavior.
This reverts commit 7bdc7635b885e473f6a577264fd8efad1c02174f, reversing
changes made to 45786be516e13d55a1fca9a4abaddd5781209103.
|
| |
|
| |
|
|
|
|
| |
Fixes #18787.
|
|
|
|
| |
Now all strings will be handled as a URL.
|
| |
|
|\
| |
| |
| |
| | |
ziggythehamster/activerecord-connectionhandling-RAILS_ENV-without-rails
If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"] in ActiveRecord::ConnectionHandling
|
| |
| |
| |
| |
| |
| |
| | |
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.
|
|/
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Fixes #15705.
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
`ActiveRecord::ConnectionAdapters::Type::Value` =>
`ActiveRecord::Type::Value`
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
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`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
| |
In passing, allow multi-word adapters to be referenced in a URL:
underscored_name must become hyphened-name.
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
.. even when the supplied config made no hint that name was relevant.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
configuration
|
|
|
|
|
| |
As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure
use cases.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
.. 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.
|
|\
| |
| |
| |
| | |
tgxworld/use_teardown_helper_method_in_activerecord
Use teardown helper method.
|
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
|/
|
|
| |
mitigates #14323
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
- We have to restore DATABASE_URL to its previous state irrespective of
previous value is nil or not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
Remove FIXME tag from abstract adapter test.
|
|
|
|
|
|
|
|
| |
Rather than just changing it and hoping for the best.
Requested by @jeremy:
https://github.com/rails/rails/commit/ba1544d71628abff2777c9c514142d7e9a159111#commitcomment-2106059
|