database_flusher 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/database_flusher/active_record/deletion_strategy.rb +17 -2
- data/lib/database_flusher/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a81343383744be91dbda01a0a476b136c05cba
|
4
|
+
data.tar.gz: c060ed34325bee77a009ff4f41c15979bcd3bf18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d99764bdebeb9203adcadbd50db85b7ce3ea1293fd00af78b743e79f068b47a98249bddb7ad22a84b8809e11d6f8d633c2fc8a93bd3af0ffe8cb9bc3ffee51
|
7
|
+
data.tar.gz: 69b22da932aee52dce7c4fb7935b87255570f4b84960bf6c1d9426ddb47c0898b1df436dd8f76b96c820864b549dd1edd3971ee8c824f6ae86c060bc3f51ed9b
|
data/README.md
CHANGED
@@ -105,14 +105,23 @@ end
|
|
105
105
|
DatabaseFlusher[:active_record].strategy = :transaction
|
106
106
|
DatabaseFlusher[:mongoid].strategy = :deletion
|
107
107
|
|
108
|
-
# Use
|
109
|
-
|
108
|
+
# Use Before hook to make sure it runs after capybara driver is set.
|
109
|
+
Before do
|
110
110
|
if Capybara.current_driver == :rack_test
|
111
111
|
DatabaseFlusher[:active_record].strategy = :transaction
|
112
112
|
else
|
113
113
|
DatabaseFlusher[:active_record].strategy = :deletion
|
114
114
|
end
|
115
|
-
DatabaseFlusher.
|
115
|
+
DatabaseFlusher.start
|
116
|
+
end
|
117
|
+
|
118
|
+
# Use Around hook to make sure it runs after capybara session reset.
|
119
|
+
Around do |scenario, block|
|
120
|
+
begin
|
121
|
+
block.call
|
122
|
+
ensure
|
123
|
+
DatabaseFlusher.clean
|
124
|
+
end
|
116
125
|
end
|
117
126
|
```
|
118
127
|
|
@@ -10,16 +10,31 @@ module DatabaseFlusher
|
|
10
10
|
attr_reader :tables
|
11
11
|
|
12
12
|
class Subscriber
|
13
|
+
# INSERT [IGNORE] [INTO] schema_name.table_name
|
14
|
+
PATTERN = %r{
|
15
|
+
\A\s*
|
16
|
+
INSERT
|
17
|
+
(?:\s+IGNORE)?
|
18
|
+
(?:\s+INTO)?
|
19
|
+
\s+
|
20
|
+
(?:[`"]?([^.\s`"]+)[`"]?\.)? # schema
|
21
|
+
(?:[`"]?([^.\s`"]+)[`"]?) # table
|
22
|
+
}xi
|
23
|
+
|
13
24
|
def initialize(strategy)
|
14
25
|
@strategy = strategy
|
15
26
|
end
|
16
27
|
|
17
28
|
def call(_, _, _, _, payload)
|
18
29
|
sql = payload[:sql]
|
19
|
-
match = sql.match(
|
30
|
+
match = sql.match(PATTERN)
|
20
31
|
return unless match
|
21
|
-
table
|
32
|
+
table = match[2]
|
22
33
|
if table
|
34
|
+
schema = match[1]
|
35
|
+
if schema
|
36
|
+
table = "#{schema}.#{table}"
|
37
|
+
end
|
23
38
|
@strategy.tables << table
|
24
39
|
end
|
25
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_flusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgars Beigarts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.6.10
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: super-fast database cleaner
|