dump 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -0
- data/dump.gemspec +1 -1
- data/lib/dump/table_manipulation.rb +17 -6
- data/spec/dump/table_manipulation_spec.rb +23 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmVhZTUyMjdlMGE4YWY5ODViOGNhMDA2NDljZTljZTA3MGNmMGVkNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJkMGE4NjAxYThiYzZhYWFmNTU0ODdmMWVkZTkwMjVjY2Q3NTBhMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTAyZGM3YzNjNDk2YjJkMDAwMzIxMTY0OGRkZTdhMmRmOTQ1MGQyZmNiOWEy
|
10
|
+
Mjk1YmJjOGMwNzJmMjk2ZDUyZTcxZGJlN2U5ZDMzMTlmNTg1OWU1YjE4NmQ2
|
11
|
+
OWM5YWI2ODY0YWE4MjFkMDBlNzlmODliZjg3OWQ0YzdjODYxODI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzM2OWM4NjljYzY4YTg5YmM0NDg1ZWExYWQ1YjExMTNlYWExZjA4M2Y2MjMx
|
14
|
+
M2ZmYTdmMDQzZWY2ZDAwNTdkYTZkZTgyZjRhYWU1NGY2Njg4ZGIwMTgxMjk5
|
15
|
+
NGUxMTc1ZGY2NTdhODdjYzQxYmMwZTEwNDNlYjgzZmFiNzY1Nzk=
|
data/Gemfile
CHANGED
data/dump.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'dump'
|
5
|
-
s.version = '1.0
|
5
|
+
s.version = '1.1.0'
|
6
6
|
s.summary = %q{Rails app rake and capistrano tasks to create and restore dumps of database and assets}
|
7
7
|
s.homepage = "http://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
@@ -112,13 +112,8 @@ module Dump
|
|
112
112
|
if table_has_primary_column?(table) && row_count > chunk_size
|
113
113
|
# adapted from ActiveRecord::Batches
|
114
114
|
primary_key = table_primary_key(table)
|
115
|
-
quoted_primary_key =
|
116
|
-
"#{quote_table_name(table)}.#{quote_column_name(primary_key)}"
|
117
115
|
select_where_primary_key =
|
118
|
-
|
119
|
-
" WHERE #{quoted_primary_key} %s" \
|
120
|
-
" ORDER BY #{quoted_primary_key} ASC" \
|
121
|
-
" LIMIT #{chunk_size}"
|
116
|
+
sql_select_where_primary_key_by_adapter(table, primary_key, chunk_size)
|
122
117
|
rows = select_all_by_sql(select_where_primary_key % '>= 0')
|
123
118
|
until rows.blank?
|
124
119
|
rows.each(&block)
|
@@ -144,5 +139,21 @@ module Dump
|
|
144
139
|
def connection
|
145
140
|
ActiveRecord::Base.connection
|
146
141
|
end
|
142
|
+
|
143
|
+
def sql_select_where_primary_key_by_adapter(table, primary_key, chunk_size)
|
144
|
+
quoted_primary_key =
|
145
|
+
"#{quote_table_name(table)}.#{quote_column_name(primary_key)}"
|
146
|
+
case connection.adapter_name.downcase
|
147
|
+
when 'sqlserver'
|
148
|
+
"SELECT TOP #{chunk_size} * FROM #{quote_table_name(table)}" \
|
149
|
+
" WHERE #{quoted_primary_key} %s" \
|
150
|
+
" ORDER BY #{quoted_primary_key} ASC"
|
151
|
+
else
|
152
|
+
"SELECT * FROM #{quote_table_name(table)}" \
|
153
|
+
" WHERE #{quoted_primary_key} %s" \
|
154
|
+
" ORDER BY #{quoted_primary_key} ASC" \
|
155
|
+
" LIMIT #{chunk_size}"
|
156
|
+
end
|
157
|
+
end
|
147
158
|
end
|
148
159
|
end
|
@@ -205,20 +205,30 @@ describe Dump::TableManipulation do
|
|
205
205
|
expect(i).to eq(@row_count)
|
206
206
|
end
|
207
207
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
208
|
+
{
|
209
|
+
'whatever' =>
|
210
|
+
'SELECT * FROM [TN] WHERE [PK] %s ORDER BY [PK] ASC LIMIT 100',
|
211
|
+
'SQLServer' =>
|
212
|
+
'SELECT TOP 100 * FROM [TN] WHERE [PK] %s ORDER BY [PK] ASC',
|
213
|
+
}.each do |adapter_name, sql_template|
|
214
|
+
it 'gets rows in chunks if table has primary column and chunk size is less than row count' do
|
215
|
+
allow(connection).to receive(:adapter_name).and_return(adapter_name)
|
216
|
+
expect(self).to receive(:table_has_primary_column?).with('first').and_return(true)
|
217
|
+
expect(self).to receive(:table_chunk_size).with('first').and_return(100)
|
218
|
+
replacements = {
|
219
|
+
'[TN]' => quote_table_name('first'),
|
220
|
+
'[PK]' => "#{quote_table_name('first')}.#{quote_column_name(table_primary_key('first'))}",
|
221
|
+
}
|
222
|
+
sql = sql_template.gsub(/\[[A-Z]+\]/){ |m| replacements[m] }
|
223
|
+
|
224
|
+
expect(self).to receive(:select_all_by_sql).with(sql % '>= 0').and_return(@rows[0, 100])
|
225
|
+
5.times do |i|
|
226
|
+
last_primary_key = 100 + i * 100
|
227
|
+
expect(self).to receive(:select_all_by_sql).with(sql % "> #{last_primary_key}").and_return(@rows[last_primary_key, 100])
|
228
|
+
end
|
220
229
|
|
221
|
-
|
230
|
+
verify_getting_rows
|
231
|
+
end
|
222
232
|
end
|
223
233
|
|
224
234
|
def verify_getting_rows_in_one_pass
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: archive-tar-minitar
|