dekiru 0.7.0 → 0.8.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/README.md +43 -3
- data/lib/dekiru/data_migration_operator.rb +7 -5
- data/lib/dekiru/transaction_provider.rb +11 -0
- data/lib/dekiru/version.rb +1 -1
- data/lib/dekiru.rb +3 -1
- 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: a1c032693e2658b61ee9744b7e872a4379eb194d9f4e3a4ac1147c4b5025682b
|
4
|
+
data.tar.gz: 14321e4bf0b2574358bfc29147bf801480801181af1c8e40879d8f4357cc7fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5f36a181ddd30cf6500c5d454ceffb5cb058a5aeb5de29b1f44b96eb9eb6fe4796522bd8e0b20f0e3ae09cb5ca83f86688ac7ff1df4421522c0bbacc83ad9ac
|
7
|
+
data.tar.gz: e39f08ff48c0f412c7fbe7ff755b2c2dd77378aca03172bff6622b09d26c6bc7f94e08cefbe5ebdff575504550520da146e7b4f312b9c3b14fef6b6f96242523
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
```ruby
|
26
26
|
require 'dekiru/capybara/helpers'
|
27
27
|
RSpec.configure do |config|
|
28
|
-
config.include Dekiru::Capybara::Helpers, type: :
|
28
|
+
config.include Dekiru::Capybara::Helpers, type: :system
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
@@ -55,7 +55,7 @@ wait_for_element_position_stable(element)
|
|
55
55
|
```ruby
|
56
56
|
require 'dekiru/capybara/matchers'
|
57
57
|
RSpec.configure do |config|
|
58
|
-
config.include Dekiru::Capybara::Matchers, type: :
|
58
|
+
config.include Dekiru::Capybara::Matchers, type: :system
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
@@ -64,7 +64,7 @@ end
|
|
64
64
|
```ruby
|
65
65
|
# javascriptエラーがあったらテスト失敗するように
|
66
66
|
RSpec.configure do |config|
|
67
|
-
config.after(:each, type: :
|
67
|
+
config.after(:each, type: :system) do |example|
|
68
68
|
if example.metadata[:js] == true
|
69
69
|
expect(page).to have_no_js_errors
|
70
70
|
end
|
@@ -201,6 +201,46 @@ Dekiru.configure do |config|
|
|
201
201
|
end
|
202
202
|
```
|
203
203
|
|
204
|
+
### Dekiru::TransactionProvider
|
205
|
+
|
206
|
+
`Dekiru::DataMigrationOperator` を使うスクリプトにおいて、複数データベースへの書き込みが必要な場合など、`ActiveRecord::Base.transaction` によるトランザクション開始だけでは不十分な場合があります。`Dekiru::TransactionProvider` を実装することで `Dekiru::DataMigrationOperator` のトランザクション開始の挙動をカスタマイズすることができます。
|
207
|
+
|
208
|
+
以下のようなアプリケーションコードがあるとします。
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
class LegacyRecord < ApplicationRecord
|
212
|
+
connects_to database: { writing: :legacy, reading: :legacy }
|
213
|
+
end
|
214
|
+
|
215
|
+
class ApplicationRecord < ActiveRecord::Base
|
216
|
+
connects_to database: { writing: :primary, reading: :primary }
|
217
|
+
|
218
|
+
def self.with_legacy_transaction
|
219
|
+
ActiveRecord::Base.transaction do
|
220
|
+
LegacyRecord.transaction do
|
221
|
+
yield
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
```
|
227
|
+
|
228
|
+
`Dekiru::DataMigrationOperator` においても `ApplicationRecord.with_legacy_transaction` を使ってトランザクション開始するために、以下のような設定を用意します。
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
# config/initializer/dekiru.rb
|
232
|
+
class MyTransactionProvider < Dekiru::TransactionProvider
|
233
|
+
def within_transaction(&)
|
234
|
+
ApplicationRecord.with_legacy_transaction(&)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
Dekiru.configure do |config|
|
239
|
+
config.transaction_provider = MyTransactionProvider.new
|
240
|
+
end
|
241
|
+
```
|
242
|
+
|
243
|
+
|
204
244
|
## Refinements
|
205
245
|
|
206
246
|
### Dekiru::CamelizeHash
|
@@ -30,7 +30,7 @@ module Dekiru
|
|
30
30
|
else
|
31
31
|
raise NestedTransactionError if current_transaction_open?
|
32
32
|
|
33
|
-
@result =
|
33
|
+
@result = transaction_provider.within_transaction do
|
34
34
|
run(&block)
|
35
35
|
log "Finished execution: #{title}"
|
36
36
|
confirm?("\nAre you sure to commit?")
|
@@ -75,10 +75,6 @@ module Dekiru
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
-
def current_transaction_open?
|
79
|
-
ActiveRecord::Base.connection.current_transaction.open?
|
80
|
-
end
|
81
|
-
|
82
78
|
def log(message)
|
83
79
|
if @pb && !@pb.finished?
|
84
80
|
@pb.log(message)
|
@@ -148,5 +144,11 @@ module Dekiru
|
|
148
144
|
instance_eval(&block)
|
149
145
|
end
|
150
146
|
end
|
147
|
+
|
148
|
+
def transaction_provider
|
149
|
+
Dekiru.configuration.transaction_provider
|
150
|
+
end
|
151
|
+
|
152
|
+
delegate :current_transaction_open?, to: :transaction_provider
|
151
153
|
end
|
152
154
|
end
|
data/lib/dekiru/version.rb
CHANGED
data/lib/dekiru.rb
CHANGED
@@ -4,6 +4,7 @@ require 'dekiru/helper'
|
|
4
4
|
require 'dekiru/data_migration_operator'
|
5
5
|
require 'dekiru/mail_security_interceptor'
|
6
6
|
require 'dekiru/camelize_hash'
|
7
|
+
require 'dekiru/transaction_provider'
|
7
8
|
|
8
9
|
require 'active_support'
|
9
10
|
require 'active_support/all'
|
@@ -20,11 +21,12 @@ module Dekiru
|
|
20
21
|
end
|
21
22
|
|
22
23
|
class Configuration
|
23
|
-
attr_accessor :mail_security_hook, :maintenance_script_directory
|
24
|
+
attr_accessor :mail_security_hook, :maintenance_script_directory, :transaction_provider
|
24
25
|
|
25
26
|
def initialize
|
26
27
|
@mail_security_hook = false # default
|
27
28
|
@maintenance_script_directory = 'scripts'
|
29
|
+
@transaction_provider = TransactionProvider.new
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dekiru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akihiro Matsumura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/dekiru/railtie.rb
|
140
140
|
- lib/dekiru/task_with_logger.rb
|
141
141
|
- lib/dekiru/tasks/db.rake
|
142
|
+
- lib/dekiru/transaction_provider.rb
|
142
143
|
- lib/dekiru/version.rb
|
143
144
|
- lib/generators/maintenance_script/USAGE
|
144
145
|
- lib/generators/maintenance_script/maintenance_script_generator.rb
|