activerecord-beagle-turso 0.1.9 → 0.1.10
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/README.md +11 -0
- data/lib/active_record/connection_adapters/beagle_turso/migration_push.rb +2 -0
- data/lib/active_record/connection_adapters/beagle_turso/test_process_release.rb +77 -0
- data/lib/activerecord/beagle_turso/version.rb +1 -1
- data/lib/activerecord-beagle-turso.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85d72dcc7cf48c86d50b2e81ec3d481b0ab33c1aa3a9f1425574a82d3662c94a
|
|
4
|
+
data.tar.gz: 05c6675f967450f5f0aa66c22e0bf0244da1ed4874645d93265f13e1a0a40a77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz: '
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0937eb27407a0acf3ff4ce564181d949dc0578559faba7f76a49b41c0a597b47add6d34881df708cbae16e8629b40dcf6113fbbaed00d7703756da7c2cfca585'
|
|
7
|
+
data.tar.gz: 719662f8a03bc87f2a8b29f4f9f5d0e7ca48c66323f3b3258a67abd0f833e53a08c4df1a4db5e899a45ad696a261ef2ac4d2bbe3fa6dc5fd73207e4e7f69aa51
|
data/README.md
CHANGED
|
@@ -250,6 +250,17 @@ this gem.
|
|
|
250
250
|
each sync — pick a sync cadence accordingly, or run Solid Queue in a separate
|
|
251
251
|
process.
|
|
252
252
|
|
|
253
|
+
4. **One process per database file.** A local Turso database file is locked to
|
|
254
|
+
the process that opened it (SQLite lets processes share a file; Turso does
|
|
255
|
+
not), so a second process opening it fails with `OpenError` ("... File is
|
|
256
|
+
locked by another process") while the first holds a connection. The common
|
|
257
|
+
case is handled: `bin/rails db:test:prepare test` (or `... spec`) runs the
|
|
258
|
+
tests in a child process, so when a `db:*` rake task finishes the adapter
|
|
259
|
+
releases its own file-backed connections in the rake process
|
|
260
|
+
(`BeagleTurso::TestProcessRelease`). In-memory databases, other adapters'
|
|
261
|
+
connections and `Beagle::Turso::Database`s opened outside ActiveRecord are
|
|
262
|
+
left alone.
|
|
263
|
+
|
|
253
264
|
## Known engine issue: self-referencing foreign keys
|
|
254
265
|
|
|
255
266
|
Turso's engine has open bugs with foreign keys that reference their own table
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "active_record/connection_adapters/beagle_turso/errors"
|
|
4
4
|
require "active_record/connection_adapters/beagle_turso/sync_manager"
|
|
5
|
+
require "active_record/connection_adapters/beagle_turso/test_process_release"
|
|
5
6
|
|
|
6
7
|
module ActiveRecord
|
|
7
8
|
module ConnectionAdapters
|
|
@@ -199,6 +200,7 @@ module ActiveRecord
|
|
|
199
200
|
rake_tasks do
|
|
200
201
|
require "rake"
|
|
201
202
|
MigrationPush.install!
|
|
203
|
+
TestProcessRelease.install!
|
|
202
204
|
end
|
|
203
205
|
end
|
|
204
206
|
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module ConnectionAdapters
|
|
5
|
+
module BeagleTurso
|
|
6
|
+
# Lets `bin/rails db:test:prepare test` -- the Rails CI default -- run as
|
|
7
|
+
# one command (and `db:test:prepare spec`, or any task after it that
|
|
8
|
+
# starts a process of its own).
|
|
9
|
+
#
|
|
10
|
+
# The rake test tasks do not run the tests in the rake process:
|
|
11
|
+
# Rails::TestUnit::Runner.run_from_rake starts a separate `rails test`
|
|
12
|
+
# process and waits for it (rspec-rails' `spec` task does the same). A
|
|
13
|
+
# local Turso database file is locked to the process that opened it --
|
|
14
|
+
# SQLite lets processes share a file, Turso does not -- and
|
|
15
|
+
# db:test:prepare left its connection open, so the test process could
|
|
16
|
+
# not open the database:
|
|
17
|
+
#
|
|
18
|
+
# open failed: Locking error: Failed locking file '.../storage/test.sqlite3'.
|
|
19
|
+
# File is locked by another process
|
|
20
|
+
#
|
|
21
|
+
# So when an outermost db:* task finishes, this adapter's file-backed
|
|
22
|
+
# connections in the rake process are released. A pool reconnects on
|
|
23
|
+
# its next use. In-memory databases are left alone (closing one would
|
|
24
|
+
# destroy it, and no other process can open it anyway), as are other
|
|
25
|
+
# adapters' connections.
|
|
26
|
+
module TestProcessRelease
|
|
27
|
+
# Prepended onto Rake::Task so it works whatever order the Railtie and
|
|
28
|
+
# ActiveRecord's own rake tasks load in (same approach as MigrationPush).
|
|
29
|
+
module TaskHook
|
|
30
|
+
def execute(args = nil)
|
|
31
|
+
if name.start_with?("db:")
|
|
32
|
+
TestProcessRelease.around { super }
|
|
33
|
+
else
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class << self
|
|
40
|
+
def install!
|
|
41
|
+
return if ::Rake::Task.ancestors.include?(TaskHook)
|
|
42
|
+
::Rake::Task.prepend(TaskHook)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Releases once, when the outermost db:* task finishes: a db task
|
|
46
|
+
# that invokes others (db:test:prepare -> db:test:load_schema) keeps
|
|
47
|
+
# its connection until it is done.
|
|
48
|
+
def around
|
|
49
|
+
self.depth = depth + 1
|
|
50
|
+
yield
|
|
51
|
+
ensure
|
|
52
|
+
self.depth = depth - 1
|
|
53
|
+
release_connections! if depth.zero?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def release_connections!
|
|
57
|
+
# Not loaded means nothing connected; don't load it to find out.
|
|
58
|
+
return unless defined?(::ActiveRecord::Base) && !::ActiveRecord.autoload?(:Base)
|
|
59
|
+
|
|
60
|
+
::ActiveRecord::Base.connection_handler.connection_pool_list(:all).each do |pool|
|
|
61
|
+
pool.disconnect! if releasable?(pool.db_config)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def releasable?(db_config)
|
|
66
|
+
db_config.adapter.to_s == "beagle_turso" && db_config.database.to_s != ":memory:"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def depth = Thread.current[:beagle_turso_test_process_release_depth].to_i
|
|
70
|
+
def depth=(value)
|
|
71
|
+
Thread.current[:beagle_turso_test_process_release_depth] = value
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -6,3 +6,4 @@ require "active_record/connection_adapters/beagle_turso/sync_manager"
|
|
|
6
6
|
require "active_record/connection_adapters/beagle_turso/sync_job"
|
|
7
7
|
require "active_record/connection_adapters/beagle_turso/errors"
|
|
8
8
|
require "active_record/connection_adapters/beagle_turso/migration_push"
|
|
9
|
+
require "active_record/connection_adapters/beagle_turso/test_process_release"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-beagle-turso
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- BeagleSoftwareUK
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -97,6 +97,7 @@ files:
|
|
|
97
97
|
- lib/active_record/connection_adapters/beagle_turso/migration_push.rb
|
|
98
98
|
- lib/active_record/connection_adapters/beagle_turso/sync_job.rb
|
|
99
99
|
- lib/active_record/connection_adapters/beagle_turso/sync_manager.rb
|
|
100
|
+
- lib/active_record/connection_adapters/beagle_turso/test_process_release.rb
|
|
100
101
|
- lib/active_record/connection_adapters/beagle_turso_adapter.rb
|
|
101
102
|
- lib/activerecord-beagle-turso.rb
|
|
102
103
|
- lib/activerecord/beagle_turso/version.rb
|