active_record_proxy_adapters 0.4.7 → 0.5.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/lib/active_record/connection_adapters/mysql2_proxy_adapter.rb +2 -8
- data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +2 -8
- data/lib/active_record/connection_adapters/sqlite3_proxy_adapter.rb +42 -0
- data/lib/active_record/connection_adapters/trilogy_proxy_adapter.rb +2 -8
- data/lib/active_record/tasks/sqlite3_proxy_database_tasks.rb +19 -0
- data/lib/active_record_proxy_adapters/active_record_context.rb +0 -4
- data/lib/active_record_proxy_adapters/connection_handling/sqlite3.rb +68 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +1 -0
- data/lib/active_record_proxy_adapters/hijackable.rb +2 -4
- data/lib/active_record_proxy_adapters/primary_replica_proxy.rb +0 -1
- data/lib/active_record_proxy_adapters/railtie.rb +3 -0
- data/lib/active_record_proxy_adapters/sqlite3_proxy.rb +10 -0
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- metadata +8 -5
- data/lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b25888bc158e220dfb06b349f47c467ef04dee2889a3e7ad6624ead7f2a6ed29
|
4
|
+
data.tar.gz: e0caf99eb8ae9e535a5c68a2c4a1a74471d67d023abc6afb6b1ebd5e2ade1f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbff3cd696e3e52da998dbd44d1505f207f5bd81a1fc014eb6d95d46237ed49d4793c4084ecf34c761754ffabf5372202036ec33e427b80543f085d9c03a90c9
|
7
|
+
data.tar.gz: ae8121a5a61036bce0433d040e3b27bf130fae80084f08379108943afa369101cf3cb17e7b3ea14c3770f03b9e03e30098d250a6535646cda41c5ac89e16da61
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_record/tasks/mysql2_proxy_database_tasks"
|
4
|
+
require "active_record/connection_adapters/mysql2_adapter"
|
3
5
|
require "active_record_proxy_adapters/active_record_context"
|
4
6
|
require "active_record_proxy_adapters/hijackable"
|
5
7
|
require "active_record_proxy_adapters/mysql2_proxy"
|
6
|
-
require "active_record/connection_adapters/mysql2_adapter"
|
7
|
-
require "active_record/tasks/mysql2_proxy_database_tasks"
|
8
8
|
|
9
9
|
module ActiveRecord
|
10
10
|
module ConnectionAdapters
|
@@ -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)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_record/tasks/postgresql_proxy_database_tasks"
|
4
|
+
require "active_record/connection_adapters/postgresql_adapter"
|
3
5
|
require "active_record_proxy_adapters/active_record_context"
|
4
6
|
require "active_record_proxy_adapters/hijackable"
|
5
7
|
require "active_record_proxy_adapters/postgresql_proxy"
|
6
|
-
require "active_record/connection_adapters/postgresql_adapter"
|
7
|
-
require "active_record/tasks/postgresql_proxy_database_tasks"
|
8
8
|
|
9
9
|
module ActiveRecord
|
10
10
|
module ConnectionAdapters
|
@@ -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)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record/tasks/sqlite3_proxy_database_tasks"
|
4
|
+
require "active_record/connection_adapters/sqlite3_adapter"
|
5
|
+
require "active_record_proxy_adapters/active_record_context"
|
6
|
+
require "active_record_proxy_adapters/hijackable"
|
7
|
+
require "active_record_proxy_adapters/sqlite3_proxy"
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
module ConnectionAdapters
|
11
|
+
# This adapter is a proxy to the original SQLite3Adapter, allowing the use of the
|
12
|
+
# ActiveRecordProxyAdapters::PrimaryReplicaProxy.
|
13
|
+
class SQLite3ProxyAdapter < SQLite3Adapter
|
14
|
+
include ActiveRecordProxyAdapters::Hijackable
|
15
|
+
|
16
|
+
ADAPTER_NAME = "SQLite3Proxy"
|
17
|
+
|
18
|
+
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
19
|
+
|
20
|
+
def initialize(...)
|
21
|
+
@proxy = ActiveRecordProxyAdapters::SQLite3Proxy.new(self)
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :proxy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2_or_greater?
|
34
|
+
ActiveRecord::ConnectionAdapters.register(
|
35
|
+
"sqlite3_proxy",
|
36
|
+
"ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter",
|
37
|
+
"active_record/connection_adapters/sqlite3_proxy_adapter"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
ActiveSupport.run_load_hooks(:active_record_sqlite3proxyadapter,
|
42
|
+
ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_record/tasks/trilogy_proxy_database_tasks"
|
4
|
+
require "active_record/connection_adapters/trilogy_adapter"
|
3
5
|
require "active_record_proxy_adapters/active_record_context"
|
4
6
|
require "active_record_proxy_adapters/hijackable"
|
5
7
|
require "active_record_proxy_adapters/trilogy_proxy"
|
6
|
-
require "active_record/connection_adapters/trilogy_adapter"
|
7
|
-
require "active_record/tasks/trilogy_proxy_database_tasks"
|
8
8
|
|
9
9
|
module ActiveRecord
|
10
10
|
module ConnectionAdapters
|
@@ -13,12 +13,6 @@ 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
18
|
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record_proxy_adapters/database_tasks"
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Tasks
|
7
|
+
# Defines the sqlite3 tasks for dropping, creating, loading schema and dumping schema.
|
8
|
+
# Bypasses all the proxy logic to send all requests to primary.
|
9
|
+
class SQLite3ProxyDatabaseTasks < SQLiteDatabaseTasks
|
10
|
+
include ActiveRecordProxyAdapters::DatabaseTasks
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Allow proxy adapter to run rake tasks, i.e. db:drop, db:create, db:schema:load db:migrate, etc...
|
16
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(
|
17
|
+
/sqlite3_proxy/,
|
18
|
+
"ActiveRecord::Tasks::SQLite3ProxyDatabaseTasks"
|
19
|
+
)
|
@@ -47,10 +47,6 @@ module ActiveRecordProxyAdapters
|
|
47
47
|
active_record_version >= Gem::Version.new("7.0") && active_record_version < Gem::Version.new("8.0")
|
48
48
|
end
|
49
49
|
|
50
|
-
def active_record_v7_0?
|
51
|
-
active_record_version >= Gem::Version.new("7.0") && active_record_version < Gem::Version.new("7.1")
|
52
|
-
end
|
53
|
-
|
54
50
|
def active_record_v7_1_or_greater?
|
55
51
|
active_record_version >= Gem::Version.new("7.1")
|
56
52
|
end
|
@@ -0,0 +1,68 @@
|
|
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
|
@@ -3,3 +3,4 @@
|
|
3
3
|
require "active_record_proxy_adapters/connection_handling/postgresql"
|
4
4
|
require "active_record_proxy_adapters/connection_handling/mysql2"
|
5
5
|
require "active_record_proxy_adapters/connection_handling/trilogy"
|
6
|
+
require "active_record_proxy_adapters/connection_handling/sqlite3"
|
@@ -52,6 +52,8 @@ module ActiveRecordProxyAdapters
|
|
52
52
|
"_unproxied"
|
53
53
|
end
|
54
54
|
|
55
|
+
private
|
56
|
+
|
55
57
|
def proxy_method_name_for(method_name)
|
56
58
|
:"#{method_name}#{unproxied_method_suffix}"
|
57
59
|
end
|
@@ -61,10 +63,6 @@ module ActiveRecordProxyAdapters
|
|
61
63
|
def unproxied_method_suffix
|
62
64
|
self.class.unproxied_method_suffix
|
63
65
|
end
|
64
|
-
|
65
|
-
def proxy_method_name_for(method_name)
|
66
|
-
self.class.proxy_method_name_for(method_name)
|
67
|
-
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record_proxy_adapters/primary_replica_proxy"
|
4
|
+
require "active_record_proxy_adapters/active_record_context"
|
5
|
+
|
6
|
+
module ActiveRecordProxyAdapters
|
7
|
+
# Proxy to the original SQLite3Adapter, allowing the use of the ActiveRecordProxyAdapters::PrimaryReplicaProxy.
|
8
|
+
class SQLite3Proxy < PrimaryReplicaProxy
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cruz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-05-22 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -58,16 +58,18 @@ email:
|
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files:
|
61
|
-
- LICENSE.txt
|
62
61
|
- README.md
|
62
|
+
- LICENSE.txt
|
63
63
|
files:
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- lib/active_record/connection_adapters/mysql2_proxy_adapter.rb
|
67
67
|
- lib/active_record/connection_adapters/postgresql_proxy_adapter.rb
|
68
|
+
- lib/active_record/connection_adapters/sqlite3_proxy_adapter.rb
|
68
69
|
- lib/active_record/connection_adapters/trilogy_proxy_adapter.rb
|
69
70
|
- lib/active_record/tasks/mysql2_proxy_database_tasks.rb
|
70
71
|
- lib/active_record/tasks/postgresql_proxy_database_tasks.rb
|
72
|
+
- lib/active_record/tasks/sqlite3_proxy_database_tasks.rb
|
71
73
|
- lib/active_record/tasks/trilogy_proxy_database_tasks.rb
|
72
74
|
- lib/active_record_proxy_adapters.rb
|
73
75
|
- lib/active_record_proxy_adapters/active_record_context.rb
|
@@ -75,6 +77,7 @@ files:
|
|
75
77
|
- lib/active_record_proxy_adapters/connection_handling.rb
|
76
78
|
- lib/active_record_proxy_adapters/connection_handling/mysql2.rb
|
77
79
|
- lib/active_record_proxy_adapters/connection_handling/postgresql.rb
|
80
|
+
- lib/active_record_proxy_adapters/connection_handling/sqlite3.rb
|
78
81
|
- lib/active_record_proxy_adapters/connection_handling/trilogy.rb
|
79
82
|
- lib/active_record_proxy_adapters/database_tasks.rb
|
80
83
|
- lib/active_record_proxy_adapters/hijackable.rb
|
@@ -83,7 +86,7 @@ files:
|
|
83
86
|
- lib/active_record_proxy_adapters/postgresql_proxy.rb
|
84
87
|
- lib/active_record_proxy_adapters/primary_replica_proxy.rb
|
85
88
|
- lib/active_record_proxy_adapters/railtie.rb
|
86
|
-
- lib/active_record_proxy_adapters/
|
89
|
+
- lib/active_record_proxy_adapters/sqlite3_proxy.rb
|
87
90
|
- lib/active_record_proxy_adapters/trilogy_proxy.rb
|
88
91
|
- lib/active_record_proxy_adapters/version.rb
|
89
92
|
homepage: https://github.com/Nasdaq/active_record_proxy_adapters
|
@@ -109,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
112
|
- !ruby/object:Gem::Version
|
110
113
|
version: '0'
|
111
114
|
requirements: []
|
112
|
-
rubygems_version: 3.6.
|
115
|
+
rubygems_version: 3.6.2
|
113
116
|
specification_version: 4
|
114
117
|
summary: Read replica proxy adapters for ActiveRecord!
|
115
118
|
test_files: []
|
@@ -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
|