1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test
Guo Xiang Tan 45add34478
Move advisory locks to own connection handler.
Removes the use of `ActiveRecord::AdvisoryLockBase` since it inherits
from `ActiveRecord::Base` and hence share module attributes that are defined in `ActiveRecord::Base`.
This is problematic because establishing connections through
`ActiveRecord::AdvisoryLockBase` can end up changing state of the default
connection handler of `ActiveRecord::Base` leading to unexpected
behaviors in a Rails application.

In the case of https://github.com/rails/rails/issues/39157,

Running migrations with `rails db:migrate:primary_shard_one` was not working as
the application itself defined the following

```
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to shards: {
    default: { writing: :primary },
    shard_one: { writing: :primary_shard_one }
  }
end
```

In the database migrate rake task, the default connection was
established with the database config of `primary_shard_one`. However,
the default connection was altered to that of `primary` because
`ActiveRecord::AdvisoryLockBase.establish_connection` ended up loading
`ApplicationRecord` which calls `connects_to shards:`. Since all we
really need here is just a normal database connection, we can avoid
accidentally altering the default connection handler state during the migration
by creating a custom connection handler used for retrieving a connection.
2020-08-04 10:17:41 +08:00
..
active_record/connection_adapters Deduplicate various Active Record schema cache structures 2019-06-03 13:31:42 +02:00
assets
cases Move advisory locks to own connection handler. 2020-08-04 10:17:41 +08:00
fixtures Resolve attribute alias for counter cache column 2020-07-06 12:06:01 +09:00
migrations Fix occurrences Fixnum|Bignum 2018-03-04 20:44:30 +02:00
models Avoid implicit create_with for StiClass.all 2020-08-01 23:02:50 +09:00
schema Avoid double time zone converter decoration when user-defined timestamp attribute with implicit type 2020-07-20 19:56:01 +09:00
support Add Active Record Marshal forward compatibility tests 2020-07-02 14:11:51 +02:00
config.example.yml Remove more code for unsupported frontbase and ibm_db adapters 2020-04-12 11:45:28 +09:00
config.rb