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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDIxYTMyY2NlYzQxMmQwNTI5YjA1YTY3NGY5ZTRmOThkNGUwY2M2Zg==
4
+ ZmVhZTUyMjdlMGE4YWY5ODViOGNhMDA2NDljZTljZTA3MGNmMGVkNw==
5
5
  data.tar.gz: !binary |-
6
- ZTE0MDYxNmY2Yzg4MWVlYTlkNTcwMzBlZTUwOWI2M2JhN2ZjNTVlNA==
6
+ NzJkMGE4NjAxYThiYzZhYWFmNTU0ODdmMWVkZTkwMjVjY2Q3NTBhMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmYzODJlMTkyYzEzNjUxMTE1MmZhZTE3ZjRlZTBjMWY0MDhjZTAzYzZiOWY1
10
- YTdiNWEzMjA1NmRjNzBhZTBlMjJlNTVjZDNhMmI4NmViZmY1MTUwMmFjMzE3
11
- MmViZmRjODUyMGFjMzAzZjE3MmM5NTI3MmRhYjk2MTA2YjRkYWU=
9
+ ZTAyZGM3YzNjNDk2YjJkMDAwMzIxMTY0OGRkZTdhMmRmOTQ1MGQyZmNiOWEy
10
+ Mjk1YmJjOGMwNzJmMjk2ZDUyZTcxZGJlN2U5ZDMzMTlmNTg1OWU1YjE4NmQ2
11
+ OWM5YWI2ODY0YWE4MjFkMDBlNzlmODliZjg3OWQ0YzdjODYxODI=
12
12
  data.tar.gz: !binary |-
13
- OGM4YTJhMmMzOTYxNmQwZDE2MDJmY2I3NjYyMzU1ZmUxNzk2ZmVjNmM0YTY5
14
- ZmU4ZjJjZWVjYWIwZTUyMGVkYTNmYjQ2ZGM3ZTU5NWM3OTEzOGRhYTNlNTYy
15
- MDQxNTQzNWNjYzdhY2QyMzk5MzI0ZjhlNGUwYTBhYmVhZmJjNWY=
13
+ NzM2OWM4NjljYzY4YTg5YmM0NDg1ZWExYWQ1YjExMTNlYWExZjA4M2Y2MjMx
14
+ M2ZmYTdmMDQzZWY2ZDAwNTdkYTZkZTgyZjRhYWU1NGY2Njg4ZGIwMTgxMjk5
15
+ NGUxMTc1ZGY2NTdhODdjYzQxYmMwZTEwNDNlYjgzZmFiNzY1Nzk=
data/Gemfile CHANGED
@@ -13,6 +13,7 @@ else
13
13
  if RUBY_VERSION == '1.8.7'
14
14
  gem 'pg', '0.17.1'
15
15
  gem 'i18n', '0.6.11'
16
+ gem 'highline', '~> 1.6.21'
16
17
  else
17
18
  gem 'pg'
18
19
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'dump'
5
- s.version = '1.0.8'
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
- "SELECT * FROM #{quote_table_name(table)}" \
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
- it 'gets rows in chunks if table has primary column and chunk size is less than row count' do
209
- expect(self).to receive(:table_has_primary_column?).with('first').and_return(true)
210
- expect(self).to receive(:table_chunk_size).with('first').and_return(100)
211
- quoted_table_name = quote_table_name('first')
212
- quoted_primary_key = "#{quoted_table_name}.#{quote_column_name(table_primary_key('first'))}"
213
- sql = "SELECT * FROM #{quoted_table_name} WHERE #{quoted_primary_key} %s ORDER BY #{quoted_primary_key} ASC LIMIT 100"
214
-
215
- expect(self).to receive(:select_all_by_sql).with(sql % '>= 0').and_return(@rows[0, 100])
216
- 5.times do |i|
217
- last_primary_key = 100 + i * 100
218
- expect(self).to receive(:select_all_by_sql).with(sql % "> #{last_primary_key}").and_return(@rows[last_primary_key, 100])
219
- end
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
- verify_getting_rows
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.8
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-02-08 00:00:00.000000000 Z
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