Skip to content

Commit 46d35bc

Browse files
authored
add support for rails 7.0 (#13)
* add support for rails 7.0
1 parent d09f23e commit 46d35bc

File tree

12 files changed

+186
-223
lines changed

12 files changed

+186
-223
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
ruby: [3.1, 3.2, 3.3]
1212
gemfile:
1313
- Gemfile
14-
- gemfiles/rails_6_0.gemfile
1514
- gemfiles/rails_6_1.gemfile
15+
- gemfiles/rails_7_0.gemfile
1616
env:
1717
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
1818
steps:

Appraisals

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
require "appraisal/matrix"
44

5-
appraisal_matrix(rails: "~> 6.0")
5+
appraisal_matrix(rails: [">= 6.1", "< 7.1"])

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

55
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.0] - 2024-10-23
8+
### Added
9+
- Support for Rails 7.0.
10+
11+
### Removed
12+
- Removed support for Rails 6.0 and Rails 5.
13+
14+
### Changed
15+
- Clean up FiberedMysql2ConnectionFactory#fibered_mysql2_connection to better match Mysql2Adapter behavior.
16+
- Change FiberedMysql2::FiberedDatabaseConnectionPool#initialize to match ActiveRecord::ConnectionAdapters::ConnectionPool#initialize arguments.
17+
718
## [0.2.1] - 2024-08-19
819
### Fixed
9-
- Fixed bugs in Rails 6.1.
20+
- Fixed bugs in Rails 6.1
1021

1122
## [0.2.0] - 2023-01-12
1223
### Added

Gemfile.lock

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
11
PATH
22
remote: .
33
specs:
4-
fibered_mysql2 (0.2.1)
4+
fibered_mysql2 (0.3.0)
55
em-synchrony (~> 1.0)
6-
rails (>= 5.2, < 7)
6+
rails (>= 6.1, < 7.1)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
actioncable (6.1.7.8)
12-
actionpack (= 6.1.7.8)
13-
activesupport (= 6.1.7.8)
11+
actioncable (7.0.8.5)
12+
actionpack (= 7.0.8.5)
13+
activesupport (= 7.0.8.5)
1414
nio4r (~> 2.0)
1515
websocket-driver (>= 0.6.1)
16-
actionmailbox (6.1.7.8)
17-
actionpack (= 6.1.7.8)
18-
activejob (= 6.1.7.8)
19-
activerecord (= 6.1.7.8)
20-
activestorage (= 6.1.7.8)
21-
activesupport (= 6.1.7.8)
16+
actionmailbox (7.0.8.5)
17+
actionpack (= 7.0.8.5)
18+
activejob (= 7.0.8.5)
19+
activerecord (= 7.0.8.5)
20+
activestorage (= 7.0.8.5)
21+
activesupport (= 7.0.8.5)
2222
mail (>= 2.7.1)
23-
actionmailer (6.1.7.8)
24-
actionpack (= 6.1.7.8)
25-
actionview (= 6.1.7.8)
26-
activejob (= 6.1.7.8)
27-
activesupport (= 6.1.7.8)
23+
net-imap
24+
net-pop
25+
net-smtp
26+
actionmailer (7.0.8.5)
27+
actionpack (= 7.0.8.5)
28+
actionview (= 7.0.8.5)
29+
activejob (= 7.0.8.5)
30+
activesupport (= 7.0.8.5)
2831
mail (~> 2.5, >= 2.5.4)
32+
net-imap
33+
net-pop
34+
net-smtp
2935
rails-dom-testing (~> 2.0)
30-
actionpack (6.1.7.8)
31-
actionview (= 6.1.7.8)
32-
activesupport (= 6.1.7.8)
33-
rack (~> 2.0, >= 2.0.9)
36+
actionpack (7.0.8.5)
37+
actionview (= 7.0.8.5)
38+
activesupport (= 7.0.8.5)
39+
rack (~> 2.0, >= 2.2.4)
3440
rack-test (>= 0.6.3)
3541
rails-dom-testing (~> 2.0)
3642
rails-html-sanitizer (~> 1.0, >= 1.2.0)
37-
actiontext (6.1.7.8)
38-
actionpack (= 6.1.7.8)
39-
activerecord (= 6.1.7.8)
40-
activestorage (= 6.1.7.8)
41-
activesupport (= 6.1.7.8)
43+
actiontext (7.0.8.5)
44+
actionpack (= 7.0.8.5)
45+
activerecord (= 7.0.8.5)
46+
activestorage (= 7.0.8.5)
47+
activesupport (= 7.0.8.5)
48+
globalid (>= 0.6.0)
4249
nokogiri (>= 1.8.5)
43-
actionview (6.1.7.8)
44-
activesupport (= 6.1.7.8)
50+
actionview (7.0.8.5)
51+
activesupport (= 7.0.8.5)
4552
builder (~> 3.1)
4653
erubi (~> 1.4)
4754
rails-dom-testing (~> 2.0)
4855
rails-html-sanitizer (~> 1.1, >= 1.2.0)
49-
activejob (6.1.7.8)
50-
activesupport (= 6.1.7.8)
56+
activejob (7.0.8.5)
57+
activesupport (= 7.0.8.5)
5158
globalid (>= 0.3.6)
52-
activemodel (6.1.7.8)
53-
activesupport (= 6.1.7.8)
54-
activerecord (6.1.7.8)
55-
activemodel (= 6.1.7.8)
56-
activesupport (= 6.1.7.8)
57-
activestorage (6.1.7.8)
58-
actionpack (= 6.1.7.8)
59-
activejob (= 6.1.7.8)
60-
activerecord (= 6.1.7.8)
61-
activesupport (= 6.1.7.8)
59+
activemodel (7.0.8.5)
60+
activesupport (= 7.0.8.5)
61+
activerecord (7.0.8.5)
62+
activemodel (= 7.0.8.5)
63+
activesupport (= 7.0.8.5)
64+
activestorage (7.0.8.5)
65+
actionpack (= 7.0.8.5)
66+
activejob (= 7.0.8.5)
67+
activerecord (= 7.0.8.5)
68+
activesupport (= 7.0.8.5)
6269
marcel (~> 1.0)
6370
mini_mime (>= 1.1.0)
64-
activesupport (6.1.7.8)
71+
activesupport (7.0.8.5)
6572
concurrent-ruby (~> 1.0, >= 1.0.2)
6673
i18n (>= 1.6, < 2)
6774
minitest (>= 5.1)
6875
tzinfo (~> 2.0)
69-
zeitwerk (~> 2.3)
7076
appraisal (2.5.0)
7177
bundler
7278
rake
@@ -94,7 +100,7 @@ GEM
94100
eventmachine (1.2.7)
95101
globalid (1.2.1)
96102
activesupport (>= 6.1)
97-
i18n (1.14.5)
103+
i18n (1.14.6)
98104
concurrent-ruby (~> 1.0)
99105
json (2.7.2)
100106
loofah (2.22.0)
@@ -111,7 +117,7 @@ GEM
111117
mini_portile2 (2.8.7)
112118
minitest (5.25.1)
113119
mysql2 (0.5.6)
114-
net-imap (0.4.14)
120+
net-imap (0.5.0)
115121
date
116122
net-protocol
117123
net-pop (0.1.2)
@@ -131,37 +137,37 @@ GEM
131137
byebug (~> 11.0)
132138
pry (>= 0.13, < 0.15)
133139
racc (1.8.1)
134-
rack (2.2.9)
140+
rack (2.2.10)
135141
rack-test (2.1.0)
136142
rack (>= 1.3)
137-
rails (6.1.7.8)
138-
actioncable (= 6.1.7.8)
139-
actionmailbox (= 6.1.7.8)
140-
actionmailer (= 6.1.7.8)
141-
actionpack (= 6.1.7.8)
142-
actiontext (= 6.1.7.8)
143-
actionview (= 6.1.7.8)
144-
activejob (= 6.1.7.8)
145-
activemodel (= 6.1.7.8)
146-
activerecord (= 6.1.7.8)
147-
activestorage (= 6.1.7.8)
148-
activesupport (= 6.1.7.8)
143+
rails (7.0.8.5)
144+
actioncable (= 7.0.8.5)
145+
actionmailbox (= 7.0.8.5)
146+
actionmailer (= 7.0.8.5)
147+
actionpack (= 7.0.8.5)
148+
actiontext (= 7.0.8.5)
149+
actionview (= 7.0.8.5)
150+
activejob (= 7.0.8.5)
151+
activemodel (= 7.0.8.5)
152+
activerecord (= 7.0.8.5)
153+
activestorage (= 7.0.8.5)
154+
activesupport (= 7.0.8.5)
149155
bundler (>= 1.15.0)
150-
railties (= 6.1.7.8)
151-
sprockets-rails (>= 2.0.0)
156+
railties (= 7.0.8.5)
152157
rails-dom-testing (2.2.0)
153158
activesupport (>= 5.0.0)
154159
minitest
155160
nokogiri (>= 1.6)
156161
rails-html-sanitizer (1.6.0)
157162
loofah (~> 2.21)
158163
nokogiri (~> 1.14)
159-
railties (6.1.7.8)
160-
actionpack (= 6.1.7.8)
161-
activesupport (= 6.1.7.8)
164+
railties (7.0.8.5)
165+
actionpack (= 7.0.8.5)
166+
activesupport (= 7.0.8.5)
162167
method_source
163168
rake (>= 12.2)
164169
thor (~> 1.0)
170+
zeitwerk (~> 2.5)
165171
rake (13.2.1)
166172
rspec (3.13.0)
167173
rspec-core (~> 3.13.0)
@@ -181,17 +187,10 @@ GEM
181187
json (>= 1.8, < 3)
182188
simplecov-html (~> 0.10.0)
183189
simplecov-html (0.10.2)
184-
sprockets (4.2.1)
185-
concurrent-ruby (~> 1.0)
186-
rack (>= 2.2.4, < 4)
187-
sprockets-rails (3.5.2)
188-
actionpack (>= 6.1)
189-
activesupport (>= 6.1)
190-
sprockets (>= 3.0.0)
191190
sync (0.5.0)
192191
term-ansicolor (1.11.2)
193192
tins (~> 1.0)
194-
thor (1.3.1)
193+
thor (1.3.2)
195194
timeout (0.4.1)
196195
tins (1.33.0)
197196
bigdecimal
@@ -201,7 +200,7 @@ GEM
201200
websocket-driver (0.7.6)
202201
websocket-extensions (>= 0.1.0)
203202
websocket-extensions (0.1.5)
204-
zeitwerk (2.6.17)
203+
zeitwerk (2.6.18)
205204

206205
PLATFORMS
207206
ruby

fibered_mysql2.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
3030
spec.require_paths = ["lib"]
3131

3232
spec.add_dependency 'em-synchrony', '~> 1.0'
33-
spec.add_dependency 'rails', '>= 5.2', '< 7'
33+
spec.add_dependency 'rails', '>= 6.1', '< 7.1'
3434
end

gemfiles/rails_6_0.gemfile renamed to gemfiles/rails_7_0.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ gem "pry"
1111
gem "pry-byebug"
1212
gem "rake"
1313
gem "rspec"
14-
gem "rails", "~> 6.0.0"
14+
gem "rails", "~> 7.0.0"
1515

1616
gemspec path: "../"

lib/active_record/connection_adapters/fibered_mysql2_adapter.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
require 'active_record/connection_adapters/em_mysql2_adapter'
77

88
module FiberedMysql2
9-
module FiberedMysql2Adapter_4_2
10-
def lease
11-
synchronize do
12-
unless in_use?
13-
@owner = Fiber.current
14-
end
15-
end
16-
end
17-
end
18-
199
module FiberedMysql2Adapter_5_2
2010
def lease
2111
if in_use?
@@ -72,11 +62,23 @@ def owner_fiber
7262
end
7363

7464
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
75-
case ::Rails::VERSION::MAJOR
76-
when 4
77-
include FiberedMysql2Adapter_4_2
78-
when 5, 6
79-
include FiberedMysql2Adapter_5_2
65+
include FiberedMysql2Adapter_5_2
66+
67+
class << self
68+
# Copied from Mysql2Adapter, except with the EM Mysql2 client
69+
def new_client(config)
70+
Mysql2::EM::Client.new(config)
71+
rescue Mysql2::Error => error
72+
if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
73+
raise ActiveRecord::NoDatabaseError.db_error(config[:database])
74+
elsif error.error_number == ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
75+
raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
76+
elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
77+
raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
78+
else
79+
raise ActiveRecord::ConnectionNotEstablished, error.message
80+
end
81+
end
8082
end
8183

8284
def initialize(*args)

lib/fibered_mysql2/fibered_database_connection_pool.rb

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,6 @@ def mon_exit_for_cond
186186
module FiberedDatabaseConnectionPool
187187
include FiberedMonitorMixin
188188

189-
module Adapter_4_2
190-
def cached_connections
191-
@reserved_connections
192-
end
193-
194-
def current_connection_id
195-
ActiveRecord::Base.connection_id ||= Fiber.current.object_id
196-
end
197-
198-
def checkout
199-
begin
200-
reap_connections
201-
rescue => ex
202-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
203-
end
204-
super
205-
end
206-
end
207-
208189
module Adapter_5_2
209190
def cached_connections
210191
@thread_cached_conns
@@ -229,27 +210,16 @@ def release_connection(owner_thread = Fiber.current)
229210
end
230211
end
231212
end
213+
include Adapter_5_2
232214

233-
case Rails::VERSION::MAJOR
234-
when 4
235-
include Adapter_4_2
236-
when 5, 6
237-
include Adapter_5_2
238-
end
239-
240-
def initialize(connection_spec, *args, **keyword_args)
241-
if ActiveRecord.gem_version < "6.1"
242-
connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
243-
connection_spec.config[:reaping_frequency] = nil # starting in Rails 5, this defaults to 60 if not explicitly set
244-
elsif connection_spec.db_config.reaping_frequency
245-
connection_spec.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
215+
def initialize(pool_config)
216+
if pool_config.db_config.reaping_frequency
217+
pool_config.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
246218
end
247219

248-
super(connection_spec, *args, **keyword_args)
220+
super(pool_config)
249221

250222
@reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
251-
252-
# note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
253223
end
254224

255225
def connection

0 commit comments

Comments
 (0)