Skip to content

Commit 6777e42

Browse files
authored
Merge pull request #1112 from headius/rails7
Switch to jruby-head and rails 7.0
2 parents a8a5f8b + 9039199 commit 6777e42

File tree

5 files changed

+106
-23
lines changed

5 files changed

+106
-23
lines changed

.github/workflows/ruby.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
ruby-version: ['jruby-9.2.20.1']
27+
ruby-version: ['jruby-head']
2828
db: ['mysql2']
2929
test_targets: ["rails:test_mysql2"]
30-
ar_version: ["6-1-stable"]
30+
ar_version: ["7-0-stable"]
3131
prepared_statements: ['false', 'true']
3232
driver: ['MySQL']
3333

@@ -76,10 +76,10 @@ jobs:
7676
strategy:
7777
fail-fast: false
7878
matrix:
79-
ruby-version: [ 'jruby-9.2.20.1' ]
79+
ruby-version: [ 'jruby-head' ]
8080
db: [ 'postgresql' ]
8181
test_targets: [ "rails:test_postgresql" ]
82-
ar_version: ["6-1-stable"]
82+
ar_version: ["7-0-stable"]
8383
prepared_statements: [ 'false', 'true' ]
8484

8585
services:
@@ -126,10 +126,10 @@ jobs:
126126
strategy:
127127
fail-fast: false
128128
matrix:
129-
ruby-version: ['jruby-9.2.20.1']
129+
ruby-version: ['jruby-head']
130130
db: ['sqlite3']
131131
test_targets: ["rails:test_sqlite3"]
132-
ar_version: ["6-1-stable"]
132+
ar_version: ["7-0-stable"]
133133

134134
env:
135135
DB: ${{ matrix.db }}
@@ -158,7 +158,7 @@ jobs:
158158
strategy:
159159
fail-fast: false
160160
matrix:
161-
ruby-version: ['jruby-9.2.20.1']
161+
ruby-version: ['jruby-head']
162162
db: ['mysql2']
163163
test_targets: ["db:mysql test_mysql2"]
164164
prepared_statements: ['false', 'true']
@@ -203,7 +203,7 @@ jobs:
203203
strategy:
204204
fail-fast: false
205205
matrix:
206-
ruby-version: ['jruby-9.2.20.1']
206+
ruby-version: ['jruby-head']
207207
db: ['postgresql']
208208
test_targets: ["db:postgresql test_postgresql"]
209209
prepared_statements: ['false', 'true']
@@ -250,7 +250,7 @@ jobs:
250250
strategy:
251251
fail-fast: false
252252
matrix:
253-
ruby-version: ['jruby-9.2.20.1']
253+
ruby-version: ['jruby-head']
254254
db: ['sqlite3']
255255
test_targets: ['test_sqlite3']
256256

Gemfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ else
4747
gemspec name: 'activerecord-jdbc-adapter' # Use versiom from .gemspec
4848
end
4949

50-
gem 'rake', '>= 11.1', require: nil
50+
gem 'rake', require: nil
5151

5252
group :test do
53-
gem 'test-unit', '~> 2.5.4', require: nil
54-
gem 'test-unit-context', '>= 0.4.0', require: nil
53+
gem 'test-unit', require: nil
54+
gem 'test-unit-context', require: nil
5555
gem 'mocha', '~> 1.2', require: false # Rails has '~> 0.14'
5656

5757
gem 'bcrypt', '~> 3.1.11', require: false
5858
end
5959

6060
group :rails do
6161
group :test do
62-
gem 'minitest', '~> 5.12.2', require: nil
63-
gem 'minitest-excludes', '~> 2.0.1', require: nil
62+
gem 'minitest', require: nil
63+
gem 'minitest-excludes', require: nil
6464
gem 'minitest-rg', require: nil
6565

6666
gem 'benchmark-ips', require: nil

activerecord-jdbc-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Gem::Specification.new do |gem|
4141
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
4242
gem.test_files = gem.files.grep(%r{^test/})
4343

44-
gem.add_dependency 'activerecord', '~> 6.1.0'
44+
gem.add_dependency 'activerecord', '~> 7.0.2.4'
4545

4646
#gem.add_development_dependency 'test-unit', '2.5.4'
4747
#gem.add_development_dependency 'test-unit-context', '>= 0.3.0'

lib/arjdbc/abstract/database_statements.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ def exec_update(sql, name = nil, binds = NO_BINDS)
6969
end
7070
alias :exec_delete :exec_update
7171

72-
def execute(sql, name = nil)
72+
def execute(sql, name = nil, async: false)
7373
if preventing_writes? && write_query?(sql)
7474
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
7575
end
7676

7777
materialize_transactions
7878
mark_transaction_written_if_write(sql)
7979

80-
log(sql, name) { @connection.execute(sql) }
80+
log(sql, name, async: async) { @connection.execute(sql) }
8181
end
8282

8383
# overridden to support legacy binds
84-
def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil)
84+
def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil, async: false)
8585
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
8686
super
8787
end

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ module SQLite3
7979
boolean: { name: "boolean" },
8080
json: { name: "json" },
8181
}
82+
83+
class StatementPool < ConnectionAdapters::StatementPool # :nodoc:
84+
alias reset clear
8285

83-
# DIFFERENCE: class_attribute in original adapter is moved down to our section which is a class
84-
# since we cannot define it here in the module (original source this is a class).
86+
private
87+
def dealloc(stmt)
88+
stmt.close unless stmt.closed?
89+
end
90+
end
8591

8692
def initialize(connection, logger, connection_options, config)
8793
super(connection, logger, config)
@@ -101,7 +107,7 @@ def supports_transaction_isolation?
101107
end
102108

103109
def supports_partial_index?
104-
database_version >= "3.9.0"
110+
true
105111
end
106112

107113
def supports_expression_index?
@@ -144,6 +150,34 @@ def supports_insert_on_conflict?
144150
alias supports_insert_conflict_target? supports_insert_on_conflict?
145151

146152
# DIFFERENCE: active?, reconnect!, disconnect! handles by arjdbc core
153+
def supports_concurrent_connections?
154+
!@memory_database
155+
end
156+
157+
def active?
158+
!@raw_connection.closed?
159+
end
160+
161+
def reconnect!(restore_transactions: false)
162+
@lock.synchronize do
163+
if active?
164+
@connection.rollback rescue nil
165+
else
166+
connect
167+
end
168+
169+
super
170+
end
171+
end
172+
alias :reset! :reconnect!
173+
174+
# Disconnects from the database if already connected. Otherwise, this
175+
# method does nothing.
176+
def disconnect!
177+
super
178+
@connection.close rescue nil
179+
end
180+
147181

148182
def supports_index_sort_order?
149183
true
@@ -233,8 +267,8 @@ def primary_keys(table_name) # :nodoc:
233267
pks.sort_by { |f| f["pk"] }.map { |f| f["name"] }
234268
end
235269

236-
def remove_index(table_name, column_name = nil, **options) # :nodoc:
237-
return if options[:if_exists] && !index_exists?(table_name, column_name, **options)
270+
def remove_index(table_name, column_name = nil, **options) # :nodoc:
271+
return if options[:if_exists] && !index_exists?(table_name, column_name, **options)
238272

239273
index_name = index_name_for_remove(table_name, column_name, options)
240274

@@ -271,6 +305,16 @@ def remove_column(table_name, column_name, type = nil, **options) #:nodoc:
271305
end
272306
end
273307

308+
def remove_columns(table_name, *column_names, type: nil, **options) # :nodoc:
309+
alter_table(table_name) do |definition|
310+
column_names.each do |column_name|
311+
definition.remove_column column_name
312+
end
313+
column_names = column_names.map(&:to_s)
314+
definition.foreign_keys.delete_if { |fk| column_names.include?(fk.column) }
315+
end
316+
end
317+
274318
def change_column_default(table_name, column_name, default_or_changes) #:nodoc:
275319
default = extract_new_default_value(default_or_changes)
276320

@@ -380,6 +424,34 @@ def table_structure(table_name)
380424
end
381425
alias column_definitions table_structure
382426

427+
def extract_value_from_default(default)
428+
case default
429+
when /^null$/i
430+
nil
431+
# Quoted types
432+
when /^'(.*)'$/m
433+
$1.gsub("''", "'")
434+
# Quoted types
435+
when /^"(.*)"$/m
436+
$1.gsub('""', '"')
437+
# Numeric types
438+
when /\A-?\d+(\.\d*)?\z/
439+
$&
440+
else
441+
# Anything else is blank or some function
442+
# and we can't know the value of that, so return nil.
443+
nil
444+
end
445+
end
446+
447+
def extract_default_function(default_value, default)
448+
default if has_default_function?(default_value, default)
449+
end
450+
451+
def has_default_function?(default_value, default)
452+
!default_value && %r{\w+\(.*\)|CURRENT_TIME|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default)
453+
end
454+
383455
# See: https://www.sqlite.org/lang_altertable.html
384456
# SQLite has an additional restriction on the ALTER TABLE statement
385457
def invalid_alter_table_type?(type, options)
@@ -564,6 +636,17 @@ def arel_visitor
564636
Arel::Visitors::SQLite.new(self)
565637
end
566638

639+
def build_statement_pool
640+
StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
641+
end
642+
643+
def connect
644+
@connection = ::SQLite3::Database.new(
645+
@config[:database].to_s,
646+
@config.merge(results_as_hash: true)
647+
)
648+
end
649+
567650
def configure_connection
568651
execute("PRAGMA foreign_keys = ON", "SCHEMA")
569652
end

0 commit comments

Comments
 (0)