activerecord-enhancedsqlite3-adapter 0.8.0 → 0.9.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/CHANGELOG.md +5 -0
- data/README.md +17 -0
- data/gemfiles/rails_7_1.gemfile +13 -0
- data/gemfiles/rails_7_2.gemfile +13 -0
- data/gemfiles/rails_8_0.gemfile +13 -0
- data/gemfiles/rails_8_1.gemfile +13 -0
- data/lib/activerecord-enhancedsqlite3-adapter.rb +38 -0
- data/lib/enhanced_sqlite3/adapter.rb +0 -43
- data/lib/enhanced_sqlite3/extension_loading.rb +40 -0
- data/lib/enhanced_sqlite3/isolated_connection_pools.rb +22 -0
- data/lib/enhanced_sqlite3/railtie.rb +8 -1
- data/lib/enhanced_sqlite3/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a033cc5a2b9a6a98882029d495ce9432e617a38ec45692a2126d509f3a403c0
|
|
4
|
+
data.tar.gz: a0a2be9bbe710c2a410638cd4c5d1967bd53ca643f3fe0f9d8708375eaf9770e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73d8b3e7d72a198c3b3d8b4e3ebb05a21c23f264089b061a73c418175ad7265410852aa2bf15e963faf4139cddf9e43cba16d80a2efbf855db9bc9feaaa26bd9
|
|
7
|
+
data.tar.gz: 641c7e7278de2753d17b0c969e432c3cc41945be9d62bc639646b96a1bb20000dbe1980b545344c6eb31276f84e051c997de65a1f4bab299fcb8aa4cf71dc763
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.9.0] - 2026-10-13
|
|
4
|
+
|
|
5
|
+
- On Rails 8 and later, leave the SQLite3 adapter untouched and print a deprecation warning, since Rails ships these enhancements itself; `isolate_connection_pools` still works, and on Rails 8.0 `extensions:` are still loaded ([#24](https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter/issues/24))
|
|
6
|
+
- Test against Rails 7.1, 7.2, 8.0 and 8.1 in CI
|
|
7
|
+
|
|
3
8
|
## [0.8.0] - 2024-05-05
|
|
4
9
|
|
|
5
10
|
- Load `sqlpkg` extensions if listed and present ([@fractaledmind](https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter/pull/17))
|
data/README.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# ActiveRecord Enhanced SQLite3 Adapter
|
|
2
2
|
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> **You do not need this gem on Rails 8 or later.** Rails 8 ships everything below except isolated connection pools:
|
|
5
|
+
>
|
|
6
|
+
> | This gem | Rails |
|
|
7
|
+
> |---|---|
|
|
8
|
+
> | Generated columns, deferred foreign keys, `INSERT … RETURNING` | built in since 7.1 / 7.2 |
|
|
9
|
+
> | `IMMEDIATE` transactions and a non-blocking busy timeout | built in since 7.2 |
|
|
10
|
+
> | `pragmas:` in `config/database.yml` | built in since 8.0 |
|
|
11
|
+
> | `extensions:` in `config/database.yml` | built in since 8.1 |
|
|
12
|
+
>
|
|
13
|
+
> From version 0.9.0, on Rails 8 the gem leaves the SQLite3 adapter untouched and prints a deprecation warning at boot. Remove it from your Gemfile. Two exceptions:
|
|
14
|
+
>
|
|
15
|
+
> * On Rails 8.0 the gem still loads `extensions:`, which Rails itself reads only from 8.1. Keep the gem until you upgrade if you use them.
|
|
16
|
+
> * `isolate_connection_pools` still works on Rails 8, but it is experimental and will not be developed further.
|
|
17
|
+
>
|
|
18
|
+
> On Rails 7.1 and 7.2 the gem works as before.
|
|
19
|
+
|
|
3
20
|
Enhance ActiveRecord's 7.1 SQLite3 adapter. Adds support for:
|
|
4
21
|
|
|
5
22
|
* generated columns,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gemspec path: ".."
|
|
6
|
+
|
|
7
|
+
gem "activerecord", "~> 7.1.0"
|
|
8
|
+
gem "railties", "~> 7.1.0"
|
|
9
|
+
gem "sqlite3", ">= 2.1"
|
|
10
|
+
|
|
11
|
+
gem "rake", "~> 13.0"
|
|
12
|
+
gem "minitest", "~> 5.0"
|
|
13
|
+
gem "standard", "~> 1.30.0"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gemspec path: ".."
|
|
6
|
+
|
|
7
|
+
gem "activerecord", "~> 7.2.0"
|
|
8
|
+
gem "railties", "~> 7.2.0"
|
|
9
|
+
gem "sqlite3", ">= 2.1"
|
|
10
|
+
|
|
11
|
+
gem "rake", "~> 13.0"
|
|
12
|
+
gem "minitest", "~> 5.0"
|
|
13
|
+
gem "standard", "~> 1.30.0"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gemspec path: ".."
|
|
6
|
+
|
|
7
|
+
gem "activerecord", "~> 8.0.0"
|
|
8
|
+
gem "railties", "~> 8.0.0"
|
|
9
|
+
gem "sqlite3", ">= 2.1"
|
|
10
|
+
|
|
11
|
+
gem "rake", "~> 13.0"
|
|
12
|
+
gem "minitest", "~> 5.0"
|
|
13
|
+
gem "standard", "~> 1.30.0"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gemspec path: ".."
|
|
6
|
+
|
|
7
|
+
gem "activerecord", "~> 8.1.0"
|
|
8
|
+
gem "railties", "~> 8.1.0"
|
|
9
|
+
gem "sqlite3", ">= 2.1"
|
|
10
|
+
|
|
11
|
+
gem "rake", "~> 13.0"
|
|
12
|
+
gem "minitest", "~> 5.0"
|
|
13
|
+
gem "standard", "~> 1.30.0"
|
|
@@ -11,5 +11,43 @@ module EnhancedSQLite3
|
|
|
11
11
|
def isolate_connection_pools?
|
|
12
12
|
@isolate_connection_pools ||= @@isolate_connection_pools || false
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
# Rails 8 ships every enhancement except isolated connection pools and
|
|
16
|
+
# (until 8.1) `extensions:`, and this gem's adapter would replace Rails'
|
|
17
|
+
# own connection configuration.
|
|
18
|
+
def superseded?
|
|
19
|
+
ActiveRecord::VERSION::MAJOR >= 8
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reads_extensions_config?
|
|
23
|
+
ActiveRecord.version >= Gem::Version.new("8.1")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def deprecator
|
|
27
|
+
@deprecator ||= ActiveSupport::Deprecation.new("1.0", "activerecord-enhancedsqlite3-adapter")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def warn_if_superseded
|
|
31
|
+
return unless superseded?
|
|
32
|
+
|
|
33
|
+
remedy = if reads_extensions_config?
|
|
34
|
+
"Remove it from your Gemfile; Rails reads `pragmas:` and `extensions:` from config/database.yml itself."
|
|
35
|
+
else
|
|
36
|
+
"Rails reads `pragmas:` from config/database.yml itself; the gem only still loads `extensions:`, " \
|
|
37
|
+
"which Rails reads itself from 8.1. Remove the gem if you do not use them."
|
|
38
|
+
end
|
|
39
|
+
deprecator.warn(
|
|
40
|
+
"activerecord-enhancedsqlite3-adapter is not needed on Rails #{ActiveRecord::VERSION::STRING}. " \
|
|
41
|
+
"#{remedy} Only `isolate_connection_pools` is still unique to the gem."
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def adapter_patches
|
|
46
|
+
patches = []
|
|
47
|
+
patches << Adapter unless superseded?
|
|
48
|
+
patches << ExtensionLoading unless reads_extensions_config?
|
|
49
|
+
patches << IsolatedConnectionPools if !superseded? || isolate_connection_pools?
|
|
50
|
+
patches
|
|
51
|
+
end
|
|
14
52
|
end
|
|
15
53
|
end
|
|
@@ -44,30 +44,12 @@ module EnhancedSQLite3
|
|
|
44
44
|
configure_busy_handler_timeout
|
|
45
45
|
check_version
|
|
46
46
|
configure_pragmas
|
|
47
|
-
configure_extensions
|
|
48
47
|
|
|
49
48
|
EnhancedSQLite3::SupportsVirtualColumns.apply! unless try(:supports_virtual_columns?)
|
|
50
49
|
EnhancedSQLite3::SupportsDeferrableConstraints.apply! unless try(:supports_deferrable_constraints?)
|
|
51
50
|
EnhancedSQLite3::SupportsInsertReturning.apply! unless try(:supports_insert_returning?)
|
|
52
51
|
end
|
|
53
52
|
|
|
54
|
-
# Patch the #transaction method to ensure that all transactions are sent to the writing role database connection pool.
|
|
55
|
-
def transaction(...)
|
|
56
|
-
ActiveRecord::Base.connected_to(role: ActiveRecord.writing_role, prevent_writes: false) do
|
|
57
|
-
super(...)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Patch the #log method to ensure that all log messages are tagged with the database connection name.
|
|
62
|
-
def log(...)
|
|
63
|
-
db_connection_name = ActiveRecord::Base.connection_db_config.name
|
|
64
|
-
if Rails.logger.formatter.current_tags.include? db_connection_name
|
|
65
|
-
super
|
|
66
|
-
else
|
|
67
|
-
Rails.logger.tagged(db_connection_name) { super }
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
53
|
private
|
|
72
54
|
|
|
73
55
|
def configure_busy_handler_timeout
|
|
@@ -122,30 +104,5 @@ module EnhancedSQLite3
|
|
|
122
104
|
execute("PRAGMA #{key} = #{value}", "SCHEMA")
|
|
123
105
|
end
|
|
124
106
|
end
|
|
125
|
-
|
|
126
|
-
def configure_extensions
|
|
127
|
-
@raw_connection.enable_load_extension(true)
|
|
128
|
-
@config.fetch(:extensions, []).each do |extension_name|
|
|
129
|
-
if extension_name.include?("/")
|
|
130
|
-
raise LoadError unless Dir.exist?(".sqlpkg/#{extension_name}")
|
|
131
|
-
Dir.glob(".sqlpkg/#{extension_name}/*.{dll,so,dylib}") do |extension_path|
|
|
132
|
-
@raw_connection.load_extension(extension_path)
|
|
133
|
-
end
|
|
134
|
-
else
|
|
135
|
-
require extension_name
|
|
136
|
-
extension_classname = extension_name.camelize
|
|
137
|
-
extension_class = extension_classname.constantize
|
|
138
|
-
extension_class.load(@raw_connection)
|
|
139
|
-
end
|
|
140
|
-
rescue LoadError
|
|
141
|
-
Dir.glob(".sqlpkg/**/*.{dll,so,dylib}") do |extension_path|
|
|
142
|
-
@raw_connection.load_extension(extension_path)
|
|
143
|
-
end
|
|
144
|
-
Rails.logger.error("Failed to find the SQLite extension gem: #{extension_name}. Skipping...")
|
|
145
|
-
rescue NameError
|
|
146
|
-
Rails.logger.error("Failed to find the SQLite extension class: #{extension_classname}. Skipping...")
|
|
147
|
-
end
|
|
148
|
-
@raw_connection.enable_load_extension(false)
|
|
149
|
-
end
|
|
150
107
|
end
|
|
151
108
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EnhancedSQLite3
|
|
4
|
+
# Loads the `extensions:` listed in database.yml, which Rails reads itself from 8.1.
|
|
5
|
+
module ExtensionLoading
|
|
6
|
+
def configure_connection
|
|
7
|
+
super
|
|
8
|
+
configure_extensions
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def configure_extensions
|
|
14
|
+
return if @config.fetch(:extensions, []).empty?
|
|
15
|
+
|
|
16
|
+
@raw_connection.enable_load_extension(true)
|
|
17
|
+
@config.fetch(:extensions, []).each do |extension_name|
|
|
18
|
+
if extension_name.include?("/")
|
|
19
|
+
raise LoadError unless Dir.exist?(".sqlpkg/#{extension_name}")
|
|
20
|
+
Dir.glob(".sqlpkg/#{extension_name}/*.{dll,so,dylib}") do |extension_path|
|
|
21
|
+
@raw_connection.load_extension(extension_path)
|
|
22
|
+
end
|
|
23
|
+
else
|
|
24
|
+
require extension_name
|
|
25
|
+
extension_classname = extension_name.camelize
|
|
26
|
+
extension_class = extension_classname.constantize
|
|
27
|
+
extension_class.load(@raw_connection)
|
|
28
|
+
end
|
|
29
|
+
rescue LoadError
|
|
30
|
+
Dir.glob(".sqlpkg/**/*.{dll,so,dylib}") do |extension_path|
|
|
31
|
+
@raw_connection.load_extension(extension_path)
|
|
32
|
+
end
|
|
33
|
+
Rails.logger.error("Failed to find the SQLite extension gem: #{extension_name}. Skipping...")
|
|
34
|
+
rescue NameError
|
|
35
|
+
Rails.logger.error("Failed to find the SQLite extension class: #{extension_classname}. Skipping...")
|
|
36
|
+
end
|
|
37
|
+
@raw_connection.enable_load_extension(false)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EnhancedSQLite3
|
|
4
|
+
module IsolatedConnectionPools
|
|
5
|
+
# Patch the #transaction method to ensure that all transactions are sent to the writing role database connection pool.
|
|
6
|
+
def transaction(...)
|
|
7
|
+
ActiveRecord::Base.connected_to(role: ActiveRecord.writing_role, prevent_writes: false) do
|
|
8
|
+
super(...)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Patch the #log method to ensure that all log messages are tagged with the database connection name.
|
|
13
|
+
def log(...)
|
|
14
|
+
db_connection_name = ActiveRecord::Base.connection_db_config.name
|
|
15
|
+
if Rails.logger.formatter.current_tags.include? db_connection_name
|
|
16
|
+
super
|
|
17
|
+
else
|
|
18
|
+
Rails.logger.tagged(db_connection_name) { super }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "rails/railtie"
|
|
4
4
|
require "enhanced_sqlite3/adapter"
|
|
5
|
+
require "enhanced_sqlite3/extension_loading"
|
|
6
|
+
require "enhanced_sqlite3/isolated_connection_pools"
|
|
5
7
|
require "enhanced_sqlite3/resolver"
|
|
6
8
|
|
|
7
9
|
module EnhancedSQLite3
|
|
@@ -14,11 +16,16 @@ module EnhancedSQLite3
|
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
initializer "enhanced_sqlite3.deprecator" do |app|
|
|
20
|
+
app.deprecators[:enhanced_sqlite3] = EnhancedSQLite3.deprecator
|
|
21
|
+
EnhancedSQLite3.warn_if_superseded
|
|
22
|
+
end
|
|
23
|
+
|
|
17
24
|
# Enhance the SQLite3 ActiveRecord adapter with optimized defaults
|
|
18
25
|
initializer "enhanced_sqlite3.enhance_active_record_sqlite3adapter" do |app|
|
|
19
26
|
ActiveSupport.on_load(:active_record_sqlite3adapter) do
|
|
20
27
|
# self refers to `SQLite3Adapter` here
|
|
21
|
-
prepend
|
|
28
|
+
EnhancedSQLite3.adapter_patches.each { |patch| prepend patch }
|
|
22
29
|
end
|
|
23
30
|
end
|
|
24
31
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-enhancedsqlite3-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephen Margheim
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activerecord
|
|
@@ -108,8 +107,14 @@ files:
|
|
|
108
107
|
- LICENSE.txt
|
|
109
108
|
- README.md
|
|
110
109
|
- Rakefile
|
|
110
|
+
- gemfiles/rails_7_1.gemfile
|
|
111
|
+
- gemfiles/rails_7_2.gemfile
|
|
112
|
+
- gemfiles/rails_8_0.gemfile
|
|
113
|
+
- gemfiles/rails_8_1.gemfile
|
|
111
114
|
- lib/activerecord-enhancedsqlite3-adapter.rb
|
|
112
115
|
- lib/enhanced_sqlite3/adapter.rb
|
|
116
|
+
- lib/enhanced_sqlite3/extension_loading.rb
|
|
117
|
+
- lib/enhanced_sqlite3/isolated_connection_pools.rb
|
|
113
118
|
- lib/enhanced_sqlite3/railtie.rb
|
|
114
119
|
- lib/enhanced_sqlite3/resolver.rb
|
|
115
120
|
- lib/enhanced_sqlite3/supports_deferrable_constraints.rb
|
|
@@ -124,7 +129,6 @@ metadata:
|
|
|
124
129
|
homepage_uri: https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter
|
|
125
130
|
source_code_uri: https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter
|
|
126
131
|
changelog_uri: https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter/CHANGELOG.md
|
|
127
|
-
post_install_message:
|
|
128
132
|
rdoc_options: []
|
|
129
133
|
require_paths:
|
|
130
134
|
- lib
|
|
@@ -139,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
143
|
- !ruby/object:Gem::Version
|
|
140
144
|
version: '0'
|
|
141
145
|
requirements: []
|
|
142
|
-
rubygems_version: 3.
|
|
143
|
-
signing_key:
|
|
146
|
+
rubygems_version: 3.6.7
|
|
144
147
|
specification_version: 4
|
|
145
148
|
summary: ActiveRecord adapter for SQLite that enhances the default.
|
|
146
149
|
test_files: []
|