active_record_proxy_adapters 0.3.2 → 0.4.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +18 -0
  4. data/Appraisals +25 -0
  5. data/CHANGELOG.md +49 -0
  6. data/CODE_OF_CONDUCT.md +132 -0
  7. data/Dockerfile +21 -0
  8. data/db/mysql_structure.sql +41 -0
  9. data/db/postgresql_structure.sql +86 -0
  10. data/docker/postgres_replica/cmd.sh +9 -0
  11. data/docker-compose.yml +98 -0
  12. data/gemfiles/rails_7.0.gemfile +25 -0
  13. data/gemfiles/rails_7.0.gemfile.lock +122 -0
  14. data/gemfiles/rails_7.1.gemfile +21 -0
  15. data/gemfiles/rails_7.1.gemfile.lock +131 -0
  16. data/gemfiles/rails_7.2.gemfile +21 -0
  17. data/gemfiles/rails_7.2.gemfile.lock +129 -0
  18. data/gemfiles/rails_8.0.gemfile +21 -0
  19. data/gemfiles/rails_8.0.gemfile.lock +131 -0
  20. data/lib/active_record/connection_adapters/mysql2_proxy_adapter.rb +2 -0
  21. data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +3 -0
  22. data/lib/active_record/connection_adapters/trilogy_proxy_adapter.rb +41 -0
  23. data/lib/active_record/tasks/trilogy_proxy_database_tasks.rb +19 -0
  24. data/lib/active_record_proxy_adapters/connection_handling/mysql2.rb +29 -23
  25. data/lib/active_record_proxy_adapters/connection_handling/postgresql.rb +27 -21
  26. data/lib/active_record_proxy_adapters/connection_handling/trilogy.rb +44 -0
  27. data/lib/active_record_proxy_adapters/connection_handling.rb +1 -7
  28. data/lib/active_record_proxy_adapters/railtie.rb +1 -4
  29. data/lib/active_record_proxy_adapters/trilogy_proxy.rb +9 -0
  30. data/lib/active_record_proxy_adapters/version.rb +1 -1
  31. data/postgres_primary.dockerfile +34 -0
  32. data/postgres_replica.dockerfile +15 -0
  33. data/sig/active_record_proxy_adapters.rbs +4 -0
  34. metadata +27 -4
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ active_record_proxy_adapters (0.3.1)
5
+ activerecord (>= 7.0.0, < 8.1)
6
+ activesupport (>= 7.0.0, < 8.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.1.5.1)
12
+ activesupport (= 7.1.5.1)
13
+ activerecord (7.1.5.1)
14
+ activemodel (= 7.1.5.1)
15
+ activesupport (= 7.1.5.1)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.1.5.1)
18
+ base64
19
+ benchmark (>= 0.3)
20
+ bigdecimal
21
+ concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ connection_pool (>= 2.2.5)
23
+ drb
24
+ i18n (>= 1.6, < 2)
25
+ logger (>= 1.4.2)
26
+ minitest (>= 5.1)
27
+ mutex_m
28
+ securerandom (>= 0.3)
29
+ tzinfo (~> 2.0)
30
+ appraisal (2.5.0)
31
+ bundler
32
+ rake
33
+ thor (>= 0.14.0)
34
+ ast (2.4.2)
35
+ base64 (0.2.0)
36
+ benchmark (0.4.0)
37
+ bigdecimal (3.1.9)
38
+ concurrent-ruby (1.3.5)
39
+ connection_pool (2.5.0)
40
+ diff-lcs (1.6.0)
41
+ docile (1.4.1)
42
+ drb (2.2.1)
43
+ i18n (1.14.7)
44
+ concurrent-ruby (~> 1.0)
45
+ json (2.10.1)
46
+ language_server-protocol (3.17.0.4)
47
+ lint_roller (1.1.0)
48
+ logger (1.6.6)
49
+ minitest (5.25.4)
50
+ mutex_m (0.3.0)
51
+ mysql2 (0.5.6)
52
+ parallel (1.26.3)
53
+ parser (3.3.7.1)
54
+ ast (~> 2.4.1)
55
+ racc
56
+ pg (1.5.9)
57
+ racc (1.8.1)
58
+ rainbow (3.1.1)
59
+ rake (13.2.1)
60
+ regexp_parser (2.10.0)
61
+ rexml (3.4.0)
62
+ rspec (3.13.0)
63
+ rspec-core (~> 3.13.0)
64
+ rspec-expectations (~> 3.13.0)
65
+ rspec-mocks (~> 3.13.0)
66
+ rspec-core (3.13.3)
67
+ rspec-support (~> 3.13.0)
68
+ rspec-expectations (3.13.3)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.13.0)
71
+ rspec-mocks (3.13.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.13.0)
74
+ rspec-support (3.13.2)
75
+ rubocop (1.72.2)
76
+ json (~> 2.3)
77
+ language_server-protocol (~> 3.17.0.2)
78
+ lint_roller (~> 1.1.0)
79
+ parallel (~> 1.10)
80
+ parser (>= 3.3.0.2)
81
+ rainbow (>= 2.2.2, < 4.0)
82
+ regexp_parser (>= 2.9.3, < 3.0)
83
+ rubocop-ast (>= 1.38.0, < 2.0)
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 2.4.0, < 4.0)
86
+ rubocop-ast (1.38.0)
87
+ parser (>= 3.3.1.0)
88
+ rubocop-rspec (3.5.0)
89
+ lint_roller (~> 1.1)
90
+ rubocop (~> 1.72, >= 1.72.1)
91
+ ruby-progressbar (1.13.0)
92
+ securerandom (0.4.1)
93
+ simplecov (0.22.0)
94
+ docile (~> 1.1)
95
+ simplecov-html (~> 0.11)
96
+ simplecov_json_formatter (~> 0.1)
97
+ simplecov-cobertura (2.1.0)
98
+ rexml
99
+ simplecov (~> 0.19)
100
+ simplecov-html (0.13.1)
101
+ simplecov_json_formatter (0.1.4)
102
+ thor (1.3.2)
103
+ timeout (0.4.3)
104
+ trilogy (2.9.0)
105
+ tzinfo (2.0.6)
106
+ concurrent-ruby (~> 1.0)
107
+ unicode-display_width (3.1.4)
108
+ unicode-emoji (~> 4.0, >= 4.0.4)
109
+ unicode-emoji (4.0.4)
110
+
111
+ PLATFORMS
112
+ aarch64-linux-musl
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ active_record_proxy_adapters!
117
+ activerecord (~> 7.1.0)
118
+ activesupport (~> 7.1.0)
119
+ appraisal
120
+ mysql2 (~> 0.5)
121
+ pg (~> 1.5)
122
+ rake (~> 13.0)
123
+ rspec (~> 3.0)
124
+ rubocop (~> 1.72)
125
+ rubocop-rspec (~> 3.5.0)
126
+ simplecov
127
+ simplecov-cobertura
128
+ trilogy (~> 2.9)
129
+
130
+ BUNDLED WITH
131
+ 2.5.13
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2", "~> 0.5"
6
+ gem "pg", "~> 1.5"
7
+ gem "trilogy", "~> 2.9"
8
+ gem "rake", "~> 13.0"
9
+ gem "appraisal"
10
+ gem "activerecord", "~> 7.2.0"
11
+ gem "activesupport", "~> 7.2.0"
12
+
13
+ group :test do
14
+ gem "rspec", "~> 3.0"
15
+ gem "rubocop", "~> 1.72"
16
+ gem "rubocop-rspec", "~> 3.5.0"
17
+ gem "simplecov"
18
+ gem "simplecov-cobertura"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,129 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ active_record_proxy_adapters (0.3.1)
5
+ activerecord (>= 7.0.0, < 8.1)
6
+ activesupport (>= 7.0.0, < 8.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.2.2.1)
12
+ activesupport (= 7.2.2.1)
13
+ activerecord (7.2.2.1)
14
+ activemodel (= 7.2.2.1)
15
+ activesupport (= 7.2.2.1)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.2.2.1)
18
+ base64
19
+ benchmark (>= 0.3)
20
+ bigdecimal
21
+ concurrent-ruby (~> 1.0, >= 1.3.1)
22
+ connection_pool (>= 2.2.5)
23
+ drb
24
+ i18n (>= 1.6, < 2)
25
+ logger (>= 1.4.2)
26
+ minitest (>= 5.1)
27
+ securerandom (>= 0.3)
28
+ tzinfo (~> 2.0, >= 2.0.5)
29
+ appraisal (2.5.0)
30
+ bundler
31
+ rake
32
+ thor (>= 0.14.0)
33
+ ast (2.4.2)
34
+ base64 (0.2.0)
35
+ benchmark (0.4.0)
36
+ bigdecimal (3.1.9)
37
+ concurrent-ruby (1.3.5)
38
+ connection_pool (2.5.0)
39
+ diff-lcs (1.6.0)
40
+ docile (1.4.1)
41
+ drb (2.2.1)
42
+ i18n (1.14.7)
43
+ concurrent-ruby (~> 1.0)
44
+ json (2.10.1)
45
+ language_server-protocol (3.17.0.4)
46
+ lint_roller (1.1.0)
47
+ logger (1.6.6)
48
+ minitest (5.25.4)
49
+ mysql2 (0.5.6)
50
+ parallel (1.26.3)
51
+ parser (3.3.7.1)
52
+ ast (~> 2.4.1)
53
+ racc
54
+ pg (1.5.9)
55
+ racc (1.8.1)
56
+ rainbow (3.1.1)
57
+ rake (13.2.1)
58
+ regexp_parser (2.10.0)
59
+ rexml (3.4.0)
60
+ rspec (3.13.0)
61
+ rspec-core (~> 3.13.0)
62
+ rspec-expectations (~> 3.13.0)
63
+ rspec-mocks (~> 3.13.0)
64
+ rspec-core (3.13.3)
65
+ rspec-support (~> 3.13.0)
66
+ rspec-expectations (3.13.3)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.13.0)
69
+ rspec-mocks (3.13.2)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.13.0)
72
+ rspec-support (3.13.2)
73
+ rubocop (1.72.2)
74
+ json (~> 2.3)
75
+ language_server-protocol (~> 3.17.0.2)
76
+ lint_roller (~> 1.1.0)
77
+ parallel (~> 1.10)
78
+ parser (>= 3.3.0.2)
79
+ rainbow (>= 2.2.2, < 4.0)
80
+ regexp_parser (>= 2.9.3, < 3.0)
81
+ rubocop-ast (>= 1.38.0, < 2.0)
82
+ ruby-progressbar (~> 1.7)
83
+ unicode-display_width (>= 2.4.0, < 4.0)
84
+ rubocop-ast (1.38.0)
85
+ parser (>= 3.3.1.0)
86
+ rubocop-rspec (3.5.0)
87
+ lint_roller (~> 1.1)
88
+ rubocop (~> 1.72, >= 1.72.1)
89
+ ruby-progressbar (1.13.0)
90
+ securerandom (0.4.1)
91
+ simplecov (0.22.0)
92
+ docile (~> 1.1)
93
+ simplecov-html (~> 0.11)
94
+ simplecov_json_formatter (~> 0.1)
95
+ simplecov-cobertura (2.1.0)
96
+ rexml
97
+ simplecov (~> 0.19)
98
+ simplecov-html (0.13.1)
99
+ simplecov_json_formatter (0.1.4)
100
+ thor (1.3.2)
101
+ timeout (0.4.3)
102
+ trilogy (2.9.0)
103
+ tzinfo (2.0.6)
104
+ concurrent-ruby (~> 1.0)
105
+ unicode-display_width (3.1.4)
106
+ unicode-emoji (~> 4.0, >= 4.0.4)
107
+ unicode-emoji (4.0.4)
108
+
109
+ PLATFORMS
110
+ aarch64-linux-musl
111
+ ruby
112
+
113
+ DEPENDENCIES
114
+ active_record_proxy_adapters!
115
+ activerecord (~> 7.2.0)
116
+ activesupport (~> 7.2.0)
117
+ appraisal
118
+ mysql2 (~> 0.5)
119
+ pg (~> 1.5)
120
+ rake (~> 13.0)
121
+ rspec (~> 3.0)
122
+ rubocop (~> 1.72)
123
+ rubocop-rspec (~> 3.5.0)
124
+ simplecov
125
+ simplecov-cobertura
126
+ trilogy (~> 2.9)
127
+
128
+ BUNDLED WITH
129
+ 2.5.13
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2", "~> 0.5"
6
+ gem "pg", "~> 1.5"
7
+ gem "trilogy", "~> 2.9"
8
+ gem "rake", "~> 13.0"
9
+ gem "appraisal"
10
+ gem "activerecord", "~> 8.0.0"
11
+ gem "activesupport", "~> 8.0.0"
12
+
13
+ group :test do
14
+ gem "rspec", "~> 3.0"
15
+ gem "rubocop", "~> 1.72"
16
+ gem "rubocop-rspec", "~> 3.5.0"
17
+ gem "simplecov"
18
+ gem "simplecov-cobertura"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ active_record_proxy_adapters (0.3.1)
5
+ activerecord (>= 7.0.0, < 8.1)
6
+ activesupport (>= 7.0.0, < 8.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (8.0.1)
12
+ activesupport (= 8.0.1)
13
+ activerecord (8.0.1)
14
+ activemodel (= 8.0.1)
15
+ activesupport (= 8.0.1)
16
+ timeout (>= 0.4.0)
17
+ activesupport (8.0.1)
18
+ base64
19
+ benchmark (>= 0.3)
20
+ bigdecimal
21
+ concurrent-ruby (~> 1.0, >= 1.3.1)
22
+ connection_pool (>= 2.2.5)
23
+ drb
24
+ i18n (>= 1.6, < 2)
25
+ logger (>= 1.4.2)
26
+ minitest (>= 5.1)
27
+ securerandom (>= 0.3)
28
+ tzinfo (~> 2.0, >= 2.0.5)
29
+ uri (>= 0.13.1)
30
+ appraisal (2.5.0)
31
+ bundler
32
+ rake
33
+ thor (>= 0.14.0)
34
+ ast (2.4.2)
35
+ base64 (0.2.0)
36
+ benchmark (0.4.0)
37
+ bigdecimal (3.1.9)
38
+ concurrent-ruby (1.3.5)
39
+ connection_pool (2.5.0)
40
+ diff-lcs (1.6.0)
41
+ docile (1.4.1)
42
+ drb (2.2.1)
43
+ i18n (1.14.7)
44
+ concurrent-ruby (~> 1.0)
45
+ json (2.10.1)
46
+ language_server-protocol (3.17.0.4)
47
+ lint_roller (1.1.0)
48
+ logger (1.6.6)
49
+ minitest (5.25.4)
50
+ mysql2 (0.5.6)
51
+ parallel (1.26.3)
52
+ parser (3.3.7.1)
53
+ ast (~> 2.4.1)
54
+ racc
55
+ pg (1.5.9)
56
+ racc (1.8.1)
57
+ rainbow (3.1.1)
58
+ rake (13.2.1)
59
+ regexp_parser (2.10.0)
60
+ rexml (3.4.0)
61
+ rspec (3.13.0)
62
+ rspec-core (~> 3.13.0)
63
+ rspec-expectations (~> 3.13.0)
64
+ rspec-mocks (~> 3.13.0)
65
+ rspec-core (3.13.3)
66
+ rspec-support (~> 3.13.0)
67
+ rspec-expectations (3.13.3)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.13.0)
70
+ rspec-mocks (3.13.2)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.13.0)
73
+ rspec-support (3.13.2)
74
+ rubocop (1.72.2)
75
+ json (~> 2.3)
76
+ language_server-protocol (~> 3.17.0.2)
77
+ lint_roller (~> 1.1.0)
78
+ parallel (~> 1.10)
79
+ parser (>= 3.3.0.2)
80
+ rainbow (>= 2.2.2, < 4.0)
81
+ regexp_parser (>= 2.9.3, < 3.0)
82
+ rubocop-ast (>= 1.38.0, < 2.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (>= 2.4.0, < 4.0)
85
+ rubocop-ast (1.38.0)
86
+ parser (>= 3.3.1.0)
87
+ rubocop-rspec (3.5.0)
88
+ lint_roller (~> 1.1)
89
+ rubocop (~> 1.72, >= 1.72.1)
90
+ ruby-progressbar (1.13.0)
91
+ securerandom (0.4.1)
92
+ simplecov (0.22.0)
93
+ docile (~> 1.1)
94
+ simplecov-html (~> 0.11)
95
+ simplecov_json_formatter (~> 0.1)
96
+ simplecov-cobertura (2.1.0)
97
+ rexml
98
+ simplecov (~> 0.19)
99
+ simplecov-html (0.13.1)
100
+ simplecov_json_formatter (0.1.4)
101
+ thor (1.3.2)
102
+ timeout (0.4.3)
103
+ trilogy (2.9.0)
104
+ tzinfo (2.0.6)
105
+ concurrent-ruby (~> 1.0)
106
+ unicode-display_width (3.1.4)
107
+ unicode-emoji (~> 4.0, >= 4.0.4)
108
+ unicode-emoji (4.0.4)
109
+ uri (1.0.2)
110
+
111
+ PLATFORMS
112
+ aarch64-linux-musl
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ active_record_proxy_adapters!
117
+ activerecord (~> 8.0.0)
118
+ activesupport (~> 8.0.0)
119
+ appraisal
120
+ mysql2 (~> 0.5)
121
+ pg (~> 1.5)
122
+ rake (~> 13.0)
123
+ rspec (~> 3.0)
124
+ rubocop (~> 1.72)
125
+ rubocop-rspec (~> 3.5.0)
126
+ simplecov
127
+ simplecov-cobertura
128
+ trilogy (~> 2.9)
129
+
130
+ BUNDLED WITH
131
+ 2.5.13
@@ -37,3 +37,5 @@ if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2_or_greater?
37
37
  "active_record/connection_adapters/mysql2_proxy_adapter"
38
38
  )
39
39
  end
40
+
41
+ ActiveSupport.run_load_hooks(:active_record_mysql2proxyadapter, ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter)
@@ -41,3 +41,6 @@ if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2_or_greater?
41
41
  "active_record/connection_adapters/postgresql_proxy_adapter"
42
42
  )
43
43
  end
44
+
45
+ ActiveSupport.run_load_hooks(:active_record_postgresqlproxyadapter,
46
+ ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record/tasks/trilogy_proxy_database_tasks"
4
+ require "active_record/connection_adapters/trilogy_adapter"
5
+ require "active_record_proxy_adapters/active_record_context"
6
+ require "active_record_proxy_adapters/hijackable"
7
+ require "active_record_proxy_adapters/trilogy_proxy"
8
+
9
+ module ActiveRecord
10
+ module ConnectionAdapters
11
+ # This adapter is a proxy to the original TrilogyAdapter, allowing the use of the
12
+ # ActiveRecordProxyAdapters::PrimaryReplicaProxy.
13
+ class TrilogyProxyAdapter < TrilogyAdapter
14
+ include ActiveRecordProxyAdapters::Hijackable
15
+
16
+ ADAPTER_NAME = "TrilogyProxy"
17
+
18
+ delegate_to_proxy :execute, :exec_query
19
+
20
+ def initialize(...)
21
+ @proxy = ActiveRecordProxyAdapters::TrilogyProxy.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
+ "trilogy_proxy",
36
+ "ActiveRecord::ConnectionAdapters::TrilogyProxyAdapter",
37
+ "active_record/connection_adapters/trilogy_proxy_adapter"
38
+ )
39
+ end
40
+
41
+ ActiveSupport.run_load_hooks(:active_record_trilogyproxyadapter, ActiveRecord::ConnectionAdapters::TrilogyProxyAdapter)
@@ -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 trilogy tasks for dropping, creating, loading schema and dumping schema.
8
+ # Bypasses all the proxy logic to send all requests to primary.
9
+ class TrilogyProxyDatabaseTasks < MySQLDatabaseTasks
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
+ /trilogy_proxy/,
18
+ "ActiveRecord::Tasks::TrilogyProxyDatabaseTasks"
19
+ )
@@ -8,32 +8,38 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  module ActiveRecordProxyAdapters
11
- # Module to extend ActiveRecord::Base with the connection handling methods.
12
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
13
- module ConnectionHandling
14
- def mysql2_proxy_adapter_class
15
- ::ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter
16
- end
11
+ module Mysql2
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 mysql2_proxy_adapter_class
16
+ ::ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter
17
+ end
17
18
 
18
- # This method is a copy and paste from Rails' mysql2_connection,
19
- # replacing Mysql2Adapter by Mysql2ProxyAdapter
20
- # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
21
- def mysql2_proxy_connection(config) # rubocop:disable Metrics/MethodLength
22
- config = config.symbolize_keys
23
- config[:flags] ||= 0
19
+ # This method is a copy and paste from Rails' mysql2_connection,
20
+ # replacing Mysql2Adapter by Mysql2ProxyAdapter
21
+ # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
22
+ def mysql2_proxy_connection(config) # rubocop:disable Metrics/MethodLength
23
+ config = config.symbolize_keys
24
+ config[:flags] ||= 0
24
25
 
25
- if config[:flags].is_a? Array
26
- config[:flags].push "FOUND_ROWS"
27
- else
28
- config[:flags] |= Mysql2::Client::FOUND_ROWS
29
- end
26
+ if config[:flags].is_a? Array
27
+ config[:flags].push "FOUND_ROWS"
28
+ else
29
+ config[:flags] |= ::Mysql2::Client::FOUND_ROWS
30
+ end
30
31
 
31
- mysql2_proxy_adapter_class.new(
32
- mysql2_proxy_adapter_class.new_client(config),
33
- logger,
34
- nil,
35
- config
36
- )
32
+ mysql2_proxy_adapter_class.new(
33
+ mysql2_proxy_adapter_class.new_client(config),
34
+ logger,
35
+ nil,
36
+ config
37
+ )
38
+ end
37
39
  end
38
40
  end
39
41
  end
42
+
43
+ ActiveSupport.on_load(:active_record) do
44
+ ActiveRecord::Base.extend(ActiveRecordProxyAdapters::Mysql2::ConnectionHandling)
45
+ end
@@ -10,31 +10,37 @@ end
10
10
  module ActiveRecordProxyAdapters
11
11
  # Module to extend ActiveRecord::Base with the connection handling methods.
12
12
  # Required to make adapter work in ActiveRecord versions <= 7.2.x
13
- module ConnectionHandling
14
- def postgresql_proxy_adapter_class
15
- ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
16
- end
13
+ module PostgreSQL
14
+ module ConnectionHandling # rubocop:disable Style/Documentation
15
+ def postgresql_proxy_adapter_class
16
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
17
+ end
17
18
 
18
- # This method is a copy and paste from Rails' postgresql_connection,
19
- # replacing PostgreSQLAdapter by PostgreSQLProxyAdapter
20
- # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
21
- def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
22
- conn_params = config.symbolize_keys.compact
19
+ # This method is a copy and paste from Rails' postgresql_connection,
20
+ # replacing PostgreSQLAdapter by PostgreSQLProxyAdapter
21
+ # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
22
+ def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
23
+ conn_params = config.symbolize_keys.compact
23
24
 
24
- # Map ActiveRecords param names to PGs.
25
- conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
26
- conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
25
+ # Map ActiveRecords param names to PGs.
26
+ conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
27
+ conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
27
28
 
28
- # Forward only valid config params to PG::Connection.connect.
29
- valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
30
- conn_params.slice!(*valid_conn_param_keys)
29
+ # Forward only valid config params to PG::Connection.connect.
30
+ valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
31
+ conn_params.slice!(*valid_conn_param_keys)
31
32
 
32
- postgresql_proxy_adapter_class.new(
33
- postgresql_proxy_adapter_class.new_client(conn_params),
34
- logger,
35
- conn_params,
36
- config
37
- )
33
+ postgresql_proxy_adapter_class.new(
34
+ postgresql_proxy_adapter_class.new_client(conn_params),
35
+ logger,
36
+ conn_params,
37
+ config
38
+ )
39
+ end
38
40
  end
39
41
  end
40
42
  end
43
+
44
+ ActiveSupport.on_load(:active_record) do
45
+ ActiveRecord::Base.extend(ActiveRecordProxyAdapters::PostgreSQL::ConnectionHandling)
46
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "active_record/connection_adapters/trilogy_proxy_adapter"
5
+ rescue LoadError
6
+ # trilogy not available
7
+ return
8
+ end
9
+
10
+ module ActiveRecordProxyAdapters
11
+ module Trilogy
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 trilogy_proxy_adapter_class
16
+ ActiveRecord::ConnectionAdapters::TrilogyProxyAdapter
17
+ end
18
+
19
+ def trilogy_proxy_connection(config) # rubocop:disable Metrics/MethodLength
20
+ configuration = config.dup
21
+
22
+ # Set FOUND_ROWS capability on the connection so UPDATE queries returns number of rows
23
+ # matched rather than number of rows updated.
24
+ configuration[:found_rows] = true
25
+
26
+ options = [
27
+ configuration[:host],
28
+ configuration[:port],
29
+ configuration[:database],
30
+ configuration[:username],
31
+ configuration[:password],
32
+ configuration[:socket],
33
+ 0
34
+ ]
35
+
36
+ trilogy_proxy_adapter_class.new nil, logger, options, configuration
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ ActiveSupport.on_load(:active_record) do
43
+ ActiveRecord::Base.extend(ActiveRecordProxyAdapters::Trilogy::ConnectionHandling)
44
+ end
@@ -2,10 +2,4 @@
2
2
 
3
3
  require "active_record_proxy_adapters/connection_handling/postgresql"
4
4
  require "active_record_proxy_adapters/connection_handling/mysql2"
5
-
6
- module ActiveRecordProxyAdapters
7
- # Module to extend ActiveRecord::Base with the connection handling methods.
8
- # Required to make adapter work in ActiveRecord versions <= 7.2.x
9
- module ConnectionHandling
10
- end
11
- end
5
+ require "active_record_proxy_adapters/connection_handling/trilogy"