active_record_proxy_adapters 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/active_record/connection_adapters/mysql2_proxy_adapter.rb +0 -6
- data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +0 -6
- data/lib/active_record/connection_adapters/trilogy_proxy_adapter.rb +1 -7
- data/lib/active_record_proxy_adapters/active_record_context.rb +1 -25
- data/lib/active_record_proxy_adapters/configuration.rb +15 -1
- data/lib/active_record_proxy_adapters/connection_handling/sqlite3_proxy.rb +28 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +4 -4
- data/lib/active_record_proxy_adapters/core.rb +13 -0
- data/lib/active_record_proxy_adapters/log_subscriber.rb +1 -11
- data/lib/active_record_proxy_adapters/mixin/configuration.rb +0 -1
- data/lib/active_record_proxy_adapters/railtie.rb +5 -18
- data/lib/active_record_proxy_adapters/railties/mysql2.rb +13 -0
- data/lib/active_record_proxy_adapters/railties/postgresql.rb +21 -0
- data/lib/active_record_proxy_adapters/railties/sqlite3.rb +21 -0
- data/lib/active_record_proxy_adapters/railties/trilogy.rb +13 -0
- data/lib/active_record_proxy_adapters/trilogy_proxy.rb +1 -0
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- data/lib/active_record_proxy_adapters.rb +0 -19
- metadata +15 -13
- data/lib/active_record_proxy_adapters/connection_handling/sqlite3.rb +0 -68
- data/lib/active_record_proxy_adapters/rake.rb +0 -47
- data/lib/active_record_proxy_adapters/tasks/arpa.rake +0 -25
- data/lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb +0 -31
- /data/lib/active_record_proxy_adapters/connection_handling/{mysql2.rb → mysql2_proxy.rb} +0 -0
- /data/lib/active_record_proxy_adapters/connection_handling/{postgresql.rb → postgresql_proxy.rb} +0 -0
- /data/lib/active_record_proxy_adapters/connection_handling/{trilogy.rb → trilogy_proxy.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f404b61f94eec82c838124e111eba202e7fdbea61c07596739219749e7c76ac2
|
|
4
|
+
data.tar.gz: 930327b485fb9b7637a1b810c0cb52def9d0164777103f918862a9dd4a0a89e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d0c6210521feb5db9ce40fc476607fb862d818e16feb23d795e95f20f20b8db0b1311049a5895f6e9795ba2740cdef140ecb6ec67f5f1c7c7aec759e0a4c2ca
|
|
7
|
+
data.tar.gz: 1134342f6be3093cb5a3ddaba514ef702adb611e5646a3abd3c68073fcb7060459a39a5845983733b4c5f0bc24d5928f57e8333b7741bbb8b3fa812d9472f066
|
data/README.md
CHANGED
|
@@ -25,6 +25,18 @@ Install the gem and add to the application's Gemfile by executing:
|
|
|
25
25
|
|
|
26
26
|
$ bundle add 'active_record_proxy_adapters'
|
|
27
27
|
|
|
28
|
+
That will install and load the proxies for all Rails-supported adapters (i.e. `postgresql_proxy`, `mysql2_proxy`, `sqlite3_proxy` and `trilogy_proxy`).
|
|
29
|
+
|
|
30
|
+
If you wish to load only one specific adapter for a faster application boot, use:
|
|
31
|
+
|
|
32
|
+
$ bundle add 'active_record_proxy_adapters' --require 'active_record_proxy_adapters/railties/<postgresql|mysql2|sqlite3|trilogy>'
|
|
33
|
+
|
|
34
|
+
Or, in your Gemfile, use:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
gem "active_record_proxy_adapters", require: 'active_record_proxy_adapters/railties/<postgresql|mysql2|sqlite3|trilogy>'
|
|
38
|
+
```
|
|
39
|
+
|
|
28
40
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
29
41
|
|
|
30
42
|
$ gem install active_record_proxy_adapters
|
|
@@ -558,7 +570,7 @@ To create a proxy adapter for an existing database `FoobarAdapter`, follow these
|
|
|
558
570
|
return
|
|
559
571
|
end
|
|
560
572
|
|
|
561
|
-
# This is only required for Rails 7.
|
|
573
|
+
# This is only required for Rails 7.1 or earlier.
|
|
562
574
|
module ActiveRecordProxyAdapters
|
|
563
575
|
module Foobar
|
|
564
576
|
module ConnectionHandling
|
|
@@ -13,12 +13,6 @@ module ActiveRecord
|
|
|
13
13
|
class Mysql2ProxyAdapter < Mysql2Adapter
|
|
14
14
|
include ActiveRecordProxyAdapters::Hijackable
|
|
15
15
|
|
|
16
|
-
if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
|
|
17
|
-
require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
|
|
18
|
-
|
|
19
|
-
include ActiveRecordProxyAdapters::TransactionableProxyAR70
|
|
20
|
-
end
|
|
21
|
-
|
|
22
16
|
ADAPTER_NAME = "Mysql2Proxy"
|
|
23
17
|
|
|
24
18
|
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
|
@@ -13,12 +13,6 @@ module ActiveRecord
|
|
|
13
13
|
class PostgreSQLProxyAdapter < PostgreSQLAdapter
|
|
14
14
|
include ActiveRecordProxyAdapters::Hijackable
|
|
15
15
|
|
|
16
|
-
if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
|
|
17
|
-
require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
|
|
18
|
-
|
|
19
|
-
include ActiveRecordProxyAdapters::TransactionableProxyAR70
|
|
20
|
-
end
|
|
21
|
-
|
|
22
16
|
ADAPTER_NAME = "PostgreSQLProxy"
|
|
23
17
|
|
|
24
18
|
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
|
@@ -13,15 +13,9 @@ module ActiveRecord
|
|
|
13
13
|
class TrilogyProxyAdapter < TrilogyAdapter
|
|
14
14
|
include ActiveRecordProxyAdapters::Hijackable
|
|
15
15
|
|
|
16
|
-
if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_0?
|
|
17
|
-
require "active_record_proxy_adapters/transactionable_proxy_a_r_70"
|
|
18
|
-
|
|
19
|
-
include ActiveRecordProxyAdapters::TransactionableProxyAR70
|
|
20
|
-
end
|
|
21
|
-
|
|
22
16
|
ADAPTER_NAME = "TrilogyProxy"
|
|
23
17
|
|
|
24
|
-
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
|
18
|
+
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods, :exec_insert)
|
|
25
19
|
|
|
26
20
|
def initialize(...)
|
|
27
21
|
@proxy = ActiveRecordProxyAdapters::TrilogyProxy.new(self)
|
|
@@ -5,38 +5,18 @@ module ActiveRecordProxyAdapters
|
|
|
5
5
|
# versions of rails.
|
|
6
6
|
class ActiveRecordContext
|
|
7
7
|
delegate :reading_role, :reading_role=, :writing_role, :writing_role=, to: :ActiveRecord
|
|
8
|
-
delegate :legacy_connection_handling, :legacy_connection_handling=, to: :connection_handling_context
|
|
9
8
|
delegate :version, to: :ActiveRecord, prefix: :active_record
|
|
10
9
|
|
|
11
10
|
class << self
|
|
12
11
|
delegate_missing_to :new
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
# rubocop:disable Naming/PredicateMethod
|
|
16
|
-
NullConnectionHandlingContext = Class.new do
|
|
17
|
-
def legacy_connection_handling
|
|
18
|
-
false
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def legacy_connection_handling=(_value)
|
|
22
|
-
nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
# rubocop:enable Naming/PredicateMethod
|
|
26
|
-
|
|
27
14
|
def connection_class_for(connection)
|
|
28
15
|
return connection.connection_descriptor.name.constantize if active_record_v8_0_2_or_greater?
|
|
29
16
|
|
|
30
17
|
connection.connection_class || ActiveRecord::Base
|
|
31
18
|
end
|
|
32
19
|
|
|
33
|
-
def connection_handling_context
|
|
34
|
-
# This config option has been removed in Rails 7.1+
|
|
35
|
-
return NullConnectionHandlingContext.new if active_record_v7_1_or_greater?
|
|
36
|
-
|
|
37
|
-
ActiveRecord
|
|
38
|
-
end
|
|
39
|
-
|
|
40
20
|
def hijackable_methods
|
|
41
21
|
hijackable = %i[execute exec_query]
|
|
42
22
|
|
|
@@ -46,11 +26,7 @@ module ActiveRecordProxyAdapters
|
|
|
46
26
|
end
|
|
47
27
|
|
|
48
28
|
def active_record_v7?
|
|
49
|
-
active_record_version >= Gem::Version.new("7.
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def active_record_v7_0?
|
|
53
|
-
active_record_version >= Gem::Version.new("7.0") && active_record_version < Gem::Version.new("7.1")
|
|
29
|
+
active_record_version >= Gem::Version.new("7.1") && active_record_version < Gem::Version.new("8.0")
|
|
54
30
|
end
|
|
55
31
|
|
|
56
32
|
def active_record_v7_1_or_greater?
|
|
@@ -8,7 +8,21 @@ require "active_record_proxy_adapters/synchronizable_configuration"
|
|
|
8
8
|
require "active_support/core_ext/integer/time"
|
|
9
9
|
require "logger"
|
|
10
10
|
|
|
11
|
-
module ActiveRecordProxyAdapters
|
|
11
|
+
module ActiveRecordProxyAdapters # rubocop:disable Style/Documentation
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def configure
|
|
15
|
+
yield(config)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def bust_query_cache
|
|
19
|
+
config.cache.bust
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def config
|
|
23
|
+
@config ||= Configuration.new
|
|
24
|
+
end
|
|
25
|
+
|
|
12
26
|
# Provides a global configuration object to configure how the proxy should behave.
|
|
13
27
|
class Configuration
|
|
14
28
|
include SynchronizableConfiguration
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require "active_record/connection_adapters/sqlite3_proxy_adapter"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# sqlite3 not available
|
|
7
|
+
return
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module ActiveRecordProxyAdapters
|
|
11
|
+
module SQLite3
|
|
12
|
+
# Module to extend ActiveRecord::Base with the connection handling methods.
|
|
13
|
+
# Required to make adapter work in ActiveRecord versions <= 7.2.x
|
|
14
|
+
module ConnectionHandling
|
|
15
|
+
def sqlite3_proxy_adapter_class
|
|
16
|
+
ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def sqlite3_proxy_connection(config)
|
|
20
|
+
sqlite3_proxy_adapter_class.new(config)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
ActiveSupport.on_load(:active_record) do
|
|
27
|
+
ActiveRecord::Base.extend(ActiveRecordProxyAdapters::SQLite3::ConnectionHandling)
|
|
28
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "active_record_proxy_adapters/connection_handling/
|
|
4
|
-
require "active_record_proxy_adapters/connection_handling/
|
|
5
|
-
require "active_record_proxy_adapters/connection_handling/
|
|
6
|
-
require "active_record_proxy_adapters/connection_handling/
|
|
3
|
+
require "active_record_proxy_adapters/connection_handling/postgresql_proxy"
|
|
4
|
+
require "active_record_proxy_adapters/connection_handling/mysql2_proxy"
|
|
5
|
+
require "active_record_proxy_adapters/connection_handling/trilogy_proxy"
|
|
6
|
+
require "active_record_proxy_adapters/connection_handling/sqlite3_proxy"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_record"
|
|
4
|
+
require "active_record_proxy_adapters/version"
|
|
5
|
+
require "active_record_proxy_adapters/active_record_context"
|
|
6
|
+
require "active_record_proxy_adapters/configuration"
|
|
7
|
+
require "active_record_proxy_adapters/context"
|
|
8
|
+
require "active_record_proxy_adapters/contextualizer"
|
|
9
|
+
require "active_record_proxy_adapters/database_tasks"
|
|
10
|
+
require "active_record_proxy_adapters/errors"
|
|
11
|
+
require "active_record_proxy_adapters/hijackable"
|
|
12
|
+
require "active_record_proxy_adapters/mixin/configuration"
|
|
13
|
+
require "active_record_proxy_adapters/primary_replica_proxy"
|
|
@@ -22,22 +22,12 @@ module ActiveRecordProxyAdapters
|
|
|
22
22
|
|
|
23
23
|
def database_instance_prefix_for(event)
|
|
24
24
|
connection = event.payload[:connection]
|
|
25
|
-
db_config = connection.pool.try(:db_config)
|
|
25
|
+
db_config = connection.pool.try(:db_config)
|
|
26
26
|
connection_name = db_config.name
|
|
27
27
|
|
|
28
28
|
prefix = log_subscriber_prefix(connection_name)
|
|
29
29
|
|
|
30
30
|
"[#{prefix.call(event)}]"
|
|
31
31
|
end
|
|
32
|
-
|
|
33
|
-
class NullConfig # rubocop:disable Style/Documentation
|
|
34
|
-
def method_missing(...)
|
|
35
|
-
nil
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def respond_to_missing?(*)
|
|
39
|
-
true
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
32
|
end
|
|
43
33
|
end
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
require "active_support/core_ext/integer/time"
|
|
4
4
|
require "active_record_proxy_adapters/synchronizable_configuration"
|
|
5
5
|
require "active_record_proxy_adapters/cache_configuration"
|
|
6
|
-
require "active_record_proxy_adapters/context"
|
|
7
6
|
|
|
8
7
|
module ActiveRecordProxyAdapters
|
|
9
8
|
module Mixin
|
|
@@ -1,32 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_support"
|
|
4
|
+
require "active_record_proxy_adapters/core"
|
|
5
|
+
require "active_record_proxy_adapters/railties/postgresql"
|
|
6
|
+
require "active_record_proxy_adapters/railties/mysql2"
|
|
7
|
+
require "active_record_proxy_adapters/railties/trilogy"
|
|
8
|
+
require "active_record_proxy_adapters/railties/sqlite3"
|
|
4
9
|
|
|
5
10
|
module ActiveRecordProxyAdapters
|
|
6
11
|
# Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
|
|
7
12
|
class Railtie < Rails::Railtie
|
|
8
|
-
require "active_record_proxy_adapters/connection_handling"
|
|
9
13
|
require "active_record_proxy_adapters/middleware"
|
|
10
|
-
require "active_record_proxy_adapters/rake"
|
|
11
|
-
|
|
12
|
-
config.to_prepare do
|
|
13
|
-
Rails.autoloaders.each do |autoloader|
|
|
14
|
-
autoloader.inflector.inflect(
|
|
15
|
-
"postgresql_proxy_adapter" => "PostgreSQLProxyAdapter"
|
|
16
|
-
)
|
|
17
|
-
autoloader.inflector.inflect(
|
|
18
|
-
"sqlite3_proxy_adapter" => "SQLite3ProxyAdapter"
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
14
|
|
|
23
15
|
initializer "active_record_proxy_adapters.configure_rails_initialization" do |app|
|
|
24
16
|
app.middleware.use ActiveRecordProxyAdapters::Middleware
|
|
25
17
|
end
|
|
26
|
-
|
|
27
|
-
rake_tasks do
|
|
28
|
-
ActiveRecordProxyAdapters::Rake.load_tasks
|
|
29
|
-
ActiveRecordProxyAdapters::Rake.enhance_db_tasks
|
|
30
|
-
end
|
|
31
18
|
end
|
|
32
19
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_record_proxy_adapters/core"
|
|
5
|
+
|
|
6
|
+
module ActiveRecordProxyAdapters
|
|
7
|
+
module Railties
|
|
8
|
+
# Hooks into rails boot process to load the Mysql2 Proxy adapter.
|
|
9
|
+
class Mysql2Proxy < Rails::Railtie
|
|
10
|
+
require "active_record_proxy_adapters/connection_handling/mysql2_proxy"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_record_proxy_adapters/core"
|
|
5
|
+
|
|
6
|
+
module ActiveRecordProxyAdapters
|
|
7
|
+
module Railties
|
|
8
|
+
# Hooks into rails boot process to load the PostgreSQL Proxy adapter.
|
|
9
|
+
class PostgreSQLProxy < Rails::Railtie
|
|
10
|
+
require "active_record_proxy_adapters/connection_handling/postgresql_proxy"
|
|
11
|
+
|
|
12
|
+
config.to_prepare do
|
|
13
|
+
Rails.autoloaders.each do |autoloader|
|
|
14
|
+
autoloader.inflector.inflect(
|
|
15
|
+
"postgresql_proxy_adapter" => "PostgreSQLProxyAdapter"
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_record_proxy_adapters/core"
|
|
5
|
+
|
|
6
|
+
module ActiveRecordProxyAdapters
|
|
7
|
+
module Railties
|
|
8
|
+
# Hooks into rails boot process to load the SQLite3 Proxy adapter.
|
|
9
|
+
class SQLite3Proxy < Rails::Railtie
|
|
10
|
+
require "active_record_proxy_adapters/connection_handling/sqlite3_proxy"
|
|
11
|
+
|
|
12
|
+
config.to_prepare do
|
|
13
|
+
Rails.autoloaders.each do |autoloader|
|
|
14
|
+
autoloader.inflector.inflect(
|
|
15
|
+
"sqlite3_proxy_adapter" => "SQLite3ProxyAdapter"
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_record_proxy_adapters/core"
|
|
5
|
+
|
|
6
|
+
module ActiveRecordProxyAdapters
|
|
7
|
+
module Railties
|
|
8
|
+
# Hooks into rails boot process to load the Trilogy Proxy adapter.
|
|
9
|
+
class TrilogyProxy < Rails::Railtie
|
|
10
|
+
require "active_record_proxy_adapters/connection_handling/trilogy_proxy"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "active_record"
|
|
4
|
-
require "active_record_proxy_adapters/version"
|
|
5
|
-
require "active_record_proxy_adapters/configuration"
|
|
6
|
-
|
|
7
3
|
# The gem namespace.
|
|
8
4
|
module ActiveRecordProxyAdapters
|
|
9
|
-
class Error < StandardError; end
|
|
10
|
-
|
|
11
|
-
module_function
|
|
12
|
-
|
|
13
|
-
def configure
|
|
14
|
-
yield(config)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def bust_query_cache
|
|
18
|
-
config.cache.bust
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def config
|
|
22
|
-
@config ||= Configuration.new
|
|
23
|
-
end
|
|
24
5
|
end
|
|
25
6
|
|
|
26
7
|
require_relative "active_record_proxy_adapters/railtie" if defined?(Rails::Railtie)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_record_proxy_adapters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Cruz
|
|
@@ -15,7 +15,7 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 7.
|
|
18
|
+
version: 7.1.0
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: '8.1'
|
|
@@ -25,7 +25,7 @@ dependencies:
|
|
|
25
25
|
requirements:
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: 7.
|
|
28
|
+
version: 7.1.0
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: '8.1'
|
|
@@ -35,7 +35,7 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - ">="
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 7.
|
|
38
|
+
version: 7.1.0
|
|
39
39
|
- - "<"
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
41
|
version: '8.1'
|
|
@@ -45,7 +45,7 @@ dependencies:
|
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: 7.
|
|
48
|
+
version: 7.1.0
|
|
49
49
|
- - "<"
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
51
|
version: '8.1'
|
|
@@ -132,12 +132,13 @@ files:
|
|
|
132
132
|
- lib/active_record_proxy_adapters/cache_configuration.rb
|
|
133
133
|
- lib/active_record_proxy_adapters/configuration.rb
|
|
134
134
|
- lib/active_record_proxy_adapters/connection_handling.rb
|
|
135
|
-
- lib/active_record_proxy_adapters/connection_handling/
|
|
136
|
-
- lib/active_record_proxy_adapters/connection_handling/
|
|
137
|
-
- lib/active_record_proxy_adapters/connection_handling/
|
|
138
|
-
- lib/active_record_proxy_adapters/connection_handling/
|
|
135
|
+
- lib/active_record_proxy_adapters/connection_handling/mysql2_proxy.rb
|
|
136
|
+
- lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb
|
|
137
|
+
- lib/active_record_proxy_adapters/connection_handling/sqlite3_proxy.rb
|
|
138
|
+
- lib/active_record_proxy_adapters/connection_handling/trilogy_proxy.rb
|
|
139
139
|
- lib/active_record_proxy_adapters/context.rb
|
|
140
140
|
- lib/active_record_proxy_adapters/contextualizer.rb
|
|
141
|
+
- lib/active_record_proxy_adapters/core.rb
|
|
141
142
|
- lib/active_record_proxy_adapters/database_configuration.rb
|
|
142
143
|
- lib/active_record_proxy_adapters/database_tasks.rb
|
|
143
144
|
- lib/active_record_proxy_adapters/errors.rb
|
|
@@ -149,11 +150,12 @@ files:
|
|
|
149
150
|
- lib/active_record_proxy_adapters/postgresql_proxy.rb
|
|
150
151
|
- lib/active_record_proxy_adapters/primary_replica_proxy.rb
|
|
151
152
|
- lib/active_record_proxy_adapters/railtie.rb
|
|
152
|
-
- lib/active_record_proxy_adapters/
|
|
153
|
+
- lib/active_record_proxy_adapters/railties/mysql2.rb
|
|
154
|
+
- lib/active_record_proxy_adapters/railties/postgresql.rb
|
|
155
|
+
- lib/active_record_proxy_adapters/railties/sqlite3.rb
|
|
156
|
+
- lib/active_record_proxy_adapters/railties/trilogy.rb
|
|
153
157
|
- lib/active_record_proxy_adapters/sqlite3_proxy.rb
|
|
154
158
|
- lib/active_record_proxy_adapters/synchronizable_configuration.rb
|
|
155
|
-
- lib/active_record_proxy_adapters/tasks/arpa.rake
|
|
156
|
-
- lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb
|
|
157
159
|
- lib/active_record_proxy_adapters/trilogy_proxy.rb
|
|
158
160
|
- lib/active_record_proxy_adapters/version.rb
|
|
159
161
|
homepage: https://github.com/Nasdaq/active_record_proxy_adapters
|
|
@@ -172,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
172
174
|
requirements:
|
|
173
175
|
- - ">="
|
|
174
176
|
- !ruby/object:Gem::Version
|
|
175
|
-
version: 3.
|
|
177
|
+
version: 3.2.0
|
|
176
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
179
|
requirements:
|
|
178
180
|
- - ">="
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require "active_record/connection_adapters/sqlite3_proxy_adapter"
|
|
5
|
-
rescue LoadError
|
|
6
|
-
# sqlite3 not available
|
|
7
|
-
return
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
module ActiveRecordProxyAdapters
|
|
11
|
-
module SQLite3
|
|
12
|
-
# Module to extend ActiveRecord::Base with the connection handling methods.
|
|
13
|
-
# Required to make adapter work in ActiveRecord versions <= 7.2.x
|
|
14
|
-
module ConnectionHandling
|
|
15
|
-
def sqlite3_proxy_adapter_class
|
|
16
|
-
ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def sqlite3_proxy_connection(config)
|
|
20
|
-
connection_factory_mapping
|
|
21
|
-
.fetch("#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}")
|
|
22
|
-
.call(config)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def connection_factory_mapping
|
|
26
|
-
{
|
|
27
|
-
"7.0" => ->(config) { sqlite3_proxy_connection_ar_v70(config) },
|
|
28
|
-
"7.1" => ->(config) { sqlite3_proxy_connection_ar_v71(config) }
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def sqlite3_proxy_connection_ar_v70(config) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
|
|
33
|
-
config = config.symbolize_keys
|
|
34
|
-
|
|
35
|
-
# Require database.
|
|
36
|
-
raise ArgumentError, "No database file specified. Missing argument: database" unless config[:database]
|
|
37
|
-
|
|
38
|
-
# Allow database path relative to Rails.root, but only if the database
|
|
39
|
-
# path is not the special path that tells sqlite to build a database only
|
|
40
|
-
# in memory.
|
|
41
|
-
if ":memory:" != config[:database] && !config[:database].to_s.start_with?("file:") # rubocop:disable Style/YodaCondition
|
|
42
|
-
config[:database] = File.expand_path(config[:database], Rails.root) if defined?(Rails.root)
|
|
43
|
-
dirname = File.dirname(config[:database])
|
|
44
|
-
Dir.mkdir(dirname) unless File.directory?(dirname)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
db = ::SQLite3::Database.new(
|
|
48
|
-
config[:database].to_s,
|
|
49
|
-
config.merge(results_as_hash: true)
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
sqlite3_proxy_adapter_class.new(db, logger, nil, config)
|
|
53
|
-
rescue Errno::ENOENT => e
|
|
54
|
-
raise ActiveRecord::NoDatabaseError if e.message.include?("No such file or directory")
|
|
55
|
-
|
|
56
|
-
raise
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def sqlite3_proxy_connection_ar_v71(config)
|
|
60
|
-
sqlite3_proxy_adapter_class.new(config)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
ActiveSupport.on_load(:active_record) do
|
|
67
|
-
ActiveRecord::Base.extend(ActiveRecordProxyAdapters::SQLite3::ConnectionHandling)
|
|
68
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rake"
|
|
4
|
-
|
|
5
|
-
module ActiveRecordProxyAdapters
|
|
6
|
-
# Enhances all rails db rake tasks to stick to writer connection
|
|
7
|
-
module Rake
|
|
8
|
-
module_function
|
|
9
|
-
|
|
10
|
-
def load_tasks
|
|
11
|
-
Dir[rake_tasks_path].each { |rake_path| load(rake_path) }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def rake_tasks_path
|
|
15
|
-
File.join(__dir__, "tasks/**/*.rake")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def enhance_db_tasks
|
|
19
|
-
::Rake::Task
|
|
20
|
-
.tasks
|
|
21
|
-
.select(&enhanceable_db_task?)
|
|
22
|
-
.each { |task| task.enhance([push_to_stack_rake_task.name], &pop_from_stack_and_reenable) }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def push_to_stack_rake_task
|
|
26
|
-
::Rake::Task["arpa:push_to_stack"]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def pop_from_stack_rake_task
|
|
30
|
-
::Rake::Task["arpa:pop_from_stack"]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def pop_from_stack_and_reenable
|
|
34
|
-
proc do
|
|
35
|
-
pop_from_stack_rake_task.invoke
|
|
36
|
-
[push_to_stack_rake_task, pop_from_stack_rake_task].each(&:reenable)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def enhanceable_db_task?
|
|
41
|
-
proc do |task|
|
|
42
|
-
task_name = task.name
|
|
43
|
-
task_name.start_with?("db:") && task_name != "db:load_config"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
namespace :arpa do
|
|
4
|
-
desc "Pushes to connected_to stack before rake task is executed"
|
|
5
|
-
task :push_to_stack do
|
|
6
|
-
writing_role = ActiveRecordProxyAdapters::ActiveRecordContext.writing_role
|
|
7
|
-
|
|
8
|
-
ActiveRecord::Base.connected_to_stack << {
|
|
9
|
-
role: writing_role,
|
|
10
|
-
shard: nil,
|
|
11
|
-
prevent_writes: false,
|
|
12
|
-
klasses: [ActiveRecord::Base]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Thread.current.thread_variable_set(:arpa_rake_pushed_to_stack, true)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
desc "Pops from connected_to stack after rake task is invoked"
|
|
19
|
-
task :pop_from_stack do
|
|
20
|
-
if Thread.current.thread_variable_get(:arpa_rake_pushed_to_stack)
|
|
21
|
-
ActiveRecord::Base.connected_to_stack.pop
|
|
22
|
-
Thread.current.thread_variable_set(:arpa_rake_pushed_to_stack, nil)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveRecordProxyAdapters
|
|
4
|
-
module TransactionableProxyAR70 # rubocop:disable Style/Documentation
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
def begin_db_transaction # :nodoc:
|
|
9
|
-
bypass_proxy_or_else("BEGIN", "TRANSACTION") { super }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def commit_db_transaction # :nodoc:
|
|
13
|
-
bypass_proxy_or_else("COMMIT", "TRANSACTION") { super }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def exec_rollback_db_transaction # :nodoc:
|
|
17
|
-
bypass_proxy_or_else("ROLLBACK", "TRANSACTION") { super }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def bypass_proxy_or_else(*args)
|
|
23
|
-
method_name = proxy_method_name_for(:execute)
|
|
24
|
-
|
|
25
|
-
return public_send(method_name, *args) if respond_to?(method_name)
|
|
26
|
-
|
|
27
|
-
yield
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
File without changes
|
/data/lib/active_record_proxy_adapters/connection_handling/{postgresql.rb → postgresql_proxy.rb}
RENAMED
|
File without changes
|
|
File without changes
|