Skip to content

Commit

Permalink
Conditionally prepend SQLite Fix per AR version
Browse files Browse the repository at this point in the history
  • Loading branch information
brendon committed Mar 11, 2024
1 parent 04011cc commit d7d67e6
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions test/support/sqlite_transaction_fix.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
module SqliteTransactionFix
def begin_db_transaction # :nodoc:
log("begin transaction", "IMMEDIATE") do
with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
result = conn.transaction(:immediate)
verified!
result
module Rails71
def begin_db_transaction # :nodoc:
log("begin transaction", "TRANSACTION") do
with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
result = conn.transaction(:immediate)
verified!
result
end
end
end
end

module Rails61
def begin_db_transaction # :nodoc:
log("begin transaction", "TRANSACTION") { @connection.transaction(:immediate) }
end
end
end

module ActiveRecord
module ConnectionAdapters
class SQLiteAdapter < AbstractAdapter
prepend SqliteTransactionFix
if ActiveRecord.version >= Gem::Version.new("7.1")
prepend SqliteTransactionFix::Rails71
else
prepend SqliteTransactionFix::Rails61
end
end
end
end

0 comments on commit d7d67e6

Please sign in to comment.