database_rewinder 0.7.0 → 0.7.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db1d33a8c34c0c729cda2c399f9572fa9517154
|
4
|
+
data.tar.gz: 95bc85096e0150ef5260931297b9461b0a9e65f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db16fa1ceed189ce34db7f1c54a335014635614069d04d66e44836a18275e68d325de537d4205c86bf24dc1620b3764f5b21b14f49f9f614894781d83ba8d9b5
|
7
|
+
data.tar.gz: ba26cdae5c9433f37726c95e4d103e534f767ad3ce257f4752094716adb843171c7a803ae8f922ed1ddd2c0a0387a1de0ecb30699d68823b42f6473874fb6d5f
|
data/database_rewinder.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "database_rewinder"
|
8
|
-
spec.version = '0.7.
|
8
|
+
spec.version = '0.7.1'
|
9
9
|
spec.authors = ["Akira Matsuda"]
|
10
10
|
spec.email = ["ronnie@dio.jp"]
|
11
11
|
spec.description = "A minimalist's tiny and ultra-fast database cleaner"
|
@@ -49,10 +49,10 @@ module DatabaseRewinder
|
|
49
49
|
tables -= @except if @except.any?
|
50
50
|
return if tables.empty?
|
51
51
|
|
52
|
-
ar_conn.
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
if tables.many? && ar_conn.supports_multiple_statements?
|
53
|
+
ar_conn.execute_multiple tables.map {|t| "DELETE FROM #{ar_conn.quote_table_name(t)}"}.join(';')
|
54
|
+
else
|
55
|
+
ar_conn.disable_referential_integrity do
|
56
56
|
tables.each do |table_name|
|
57
57
|
ar_conn.execute "DELETE FROM #{ar_conn.quote_table_name(table_name)};"
|
58
58
|
end
|
@@ -11,33 +11,37 @@ module DatabaseRewinder
|
|
11
11
|
#TODO Use ADAPTER_NAME when we've dropped AR 4.1 support
|
12
12
|
case self.class.name
|
13
13
|
when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
|
14
|
-
log(sql) { @connection.exec sql }
|
14
|
+
disable_referential_integrity { log(sql) { @connection.exec sql } }
|
15
15
|
when 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
|
16
16
|
query_options = @connection.query_options.dup
|
17
17
|
if query_options[:connect_flags] & Mysql2::Client::MULTI_STATEMENTS != 0
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
disable_referential_integrity do
|
19
|
+
_result = log(sql) { @connection.query sql }
|
20
|
+
while @connection.next_result
|
21
|
+
# just to make sure that all queries are finished
|
22
|
+
_result = @connection.store_result
|
23
|
+
end
|
22
24
|
end
|
23
25
|
else
|
24
26
|
query_options[:connect_flags] |= Mysql2::Client::MULTI_STATEMENTS
|
25
27
|
# opens another connection to the DB
|
26
28
|
client = Mysql2::Client.new query_options
|
27
29
|
begin
|
28
|
-
|
30
|
+
# disable_referential_integrity
|
31
|
+
client.query("SET FOREIGN_KEY_CHECKS = 0")
|
32
|
+
_result = log(sql) { client.query sql }
|
29
33
|
while client.next_result
|
30
34
|
# just to make sure that all queries are finished
|
31
|
-
|
35
|
+
_result = client.store_result
|
32
36
|
end
|
33
37
|
ensure
|
34
38
|
client.close
|
35
39
|
end
|
36
40
|
end
|
37
41
|
when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
|
38
|
-
log(sql) { @connection.execute_batch sql }
|
42
|
+
disable_referential_integrity { log(sql) { @connection.execute_batch sql } }
|
39
43
|
else
|
40
|
-
|
44
|
+
raise 'Multiple deletion is not supported with the current database adapter.'
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -113,8 +113,8 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
|
|
113
113
|
end
|
114
114
|
|
115
115
|
test '.clean' do
|
116
|
-
|
117
|
-
|
116
|
+
bar = Bar.create! name: 'bar1'
|
117
|
+
Foo.create! name: 'foo1', bar_id: bar.id
|
118
118
|
DatabaseRewinder.clean
|
119
119
|
|
120
120
|
assert_equal 0, Foo.count
|
data/test/fake_app.rb
CHANGED
@@ -32,8 +32,8 @@ end
|
|
32
32
|
class CreateAllTables < ActiveRecord::Migration
|
33
33
|
def self.up
|
34
34
|
ActiveRecord::Base.establish_connection ENV['DB'].to_sym
|
35
|
-
create_table(:foos) {|t| t.string :name }
|
36
35
|
create_table(:bars) {|t| t.string :name }
|
36
|
+
create_table(:foos) {|t| t.string :name; t.references :bar, foreign_key: true }
|
37
37
|
create_table(:bazs) {|t| t.string :name }
|
38
38
|
|
39
39
|
test2_connection = ActiveRecord::Base.establish_connection("#{ENV['DB']}_2".to_sym).connection
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_rewinder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.5.1
|
163
|
+
rubygems_version: 2.4.5.1
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: A minimalist's tiny and ultra-fast database cleaner
|