tina4ruby 3.11.19 → 3.11.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 913dfbf6820b99da3ff8f0b5a845fb23239736ccc1db30eb958d664fba6abe9f
4
- data.tar.gz: c7c39ce01253b8dc60edc30550b004914ac9c4742ee2efabfdedab44dfe984f7
3
+ metadata.gz: b1d2fabb4883ebcdd387f24cfc0c3e858304d7498b1439798b448c89623fa56e
4
+ data.tar.gz: 592c8eac568eba0950bde87ac4fd9b7d9bfed365aa23539b2f50409ff6a1f1d9
5
5
  SHA512:
6
- metadata.gz: c926a2b39b248a45112e3f323174049ccdb0955c07ce3491a9346c837776cca37707ce54ecca21320ad71599b8d537a78eedadf4e675cd8c2b71dcfa6415ca39
7
- data.tar.gz: caf6b606d28154e7ed8ded6e2519cc4a45f10a9034644f15f82625eace4e2747dbc27d845dadf0f0881a1c180c38a465428976a7be6d7b1c52b4239f637fd793
6
+ metadata.gz: '0917b8cbeaaa155cbf223bcb009662bed7f48e03e1b9b4d96c338a17fdf2cbac4333d88c549980d650a70eb515532b83783090cb4f3896ca8f7f53fba8307347'
7
+ data.tar.gz: c9b3da407eb7823e9e7b19af1d3928329d061b5a8d77bd904d96870ea89e90d9dbd0979b3909bff66011c584e556bb2c3dfcf219a078e6ffd28d2ac75cea9a7e
@@ -109,6 +109,15 @@ module Tina4
109
109
  @pool_size = pool # 0 = single connection, N>0 = N pooled connections
110
110
  @connected = false
111
111
 
112
+ # Per-instance thread-local key for the transaction adapter pin.
113
+ # Without this pin, every Database method call rotates to a different
114
+ # pooled connection. Inside a transaction this silently breaks atomicity:
115
+ # start_transaction begins on adapter A, executes autocommit on B/C, and
116
+ # commit/rollback land on D — a no-op. start_transaction sets the pin,
117
+ # commit/rollback clear it. While pinned, current_driver returns the same
118
+ # driver for every call so the whole transaction runs on one connection.
119
+ @tx_pin_key = :"tina4_pinned_adapter_#{object_id}"
120
+
112
121
  # Query cache — off by default, opt-in via TINA4_DB_CACHE=true
113
122
  @cache_enabled = truthy?(ENV["TINA4_DB_CACHE"])
114
123
  @cache_ttl = (ENV["TINA4_DB_CACHE_TTL"] || "30").to_i
@@ -161,7 +170,14 @@ module Tina4
161
170
  end
162
171
 
163
172
  # Get the current driver — from pool (round-robin) or single connection.
173
+ #
174
+ # Inside a transaction, all calls must land on the SAME driver — otherwise
175
+ # start_transaction, execute, and commit each rotate to a different pooled
176
+ # connection and the transaction is meaningless. start_transaction pins
177
+ # the driver to the calling thread; commit/rollback release it.
164
178
  def current_driver
179
+ pinned = Thread.current[@tx_pin_key]
180
+ return pinned if pinned
165
181
  if @pool
166
182
  @pool.checkout
167
183
  else
@@ -355,27 +371,38 @@ module Tina4
355
371
 
356
372
  def transaction
357
373
  drv = current_driver
374
+ Thread.current[@tx_pin_key] = drv
358
375
  drv.begin_transaction
359
376
  yield self
360
377
  drv.commit
361
378
  rescue => e
362
- drv.rollback
379
+ drv.rollback if drv
363
380
  raise e
381
+ ensure
382
+ Thread.current[@tx_pin_key] = nil
364
383
  end
365
384
 
366
385
  # Begin a transaction without a block — matches PHP/Python/Node API.
386
+ # Pins the driver to this thread for the whole transaction so executes
387
+ # and the final commit/rollback all run on the same connection.
367
388
  def start_transaction
368
- current_driver.begin_transaction
389
+ drv = current_driver
390
+ Thread.current[@tx_pin_key] = drv
391
+ drv.begin_transaction
369
392
  end
370
393
 
371
- # Commit the current transaction matches PHP/Python/Node API.
394
+ # Commit the current transaction and release the driver pin.
372
395
  def commit
373
396
  current_driver.commit
397
+ ensure
398
+ Thread.current[@tx_pin_key] = nil
374
399
  end
375
400
 
376
- # Roll back the current transaction matches PHP/Python/Node API.
401
+ # Roll back the current transaction and release the driver pin.
377
402
  def rollback
378
403
  current_driver.rollback
404
+ ensure
405
+ Thread.current[@tx_pin_key] = nil
379
406
  end
380
407
 
381
408
  def tables
data/lib/tina4/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tina4
4
- VERSION = "3.11.19"
4
+ VERSION = "3.11.32"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.19
4
+ version: 3.11.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-25 00:00:00.000000000 Z
11
+ date: 2026-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack