database_sanitizer 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa2e988b212e373683438dbdae3e9e6ccb2e05bc
4
- data.tar.gz: 2396855b8ff999f66d4a98ce485a4bf06c5fabd1
3
+ metadata.gz: 77d9e46bfe3e7f9f5bd05c51eb1925384a0eb69d
4
+ data.tar.gz: 7ca1d69283a346ec4faecf93ea7c1e648c1a39ec
5
5
  SHA512:
6
- metadata.gz: 3c3086cc1d9a61bca8a7ae9a8ac6f66f12334824742778ab1b73818d1c68a24dfee4f0a5beda99daebedebbab64f851230df5b3750378caf024e929c8a4be08d
7
- data.tar.gz: dc8d3fadf65091fec225270929023892f7dc605a09c2bf4e43b414ac4bd2aa0bf7d42d1cbbb4e3c7e50c55055c147f4807aa22785ef20b9792406581258fdcc4
6
+ metadata.gz: b0acd414b98a2100ec34b58520ac52e11927c8b4ba7981f6ab2ffec1ec85cea8c798d85913c7382a1ad9a17148086a87f3469097f1fe31daa22b9a8a855e77f0
7
+ data.tar.gz: 53c1293ab81f599e72688cdf94c15d6846d760c0cb11bd38dc2c91da89ac13d29e60f2d0b8d9adc1a069e1d0fc5a0838d56b104ef5a0a7744660bc37e39e0980
@@ -69,11 +69,15 @@ module DatabaseSanitizer
69
69
  tables.with_progress('Exporting').each do |table|
70
70
  q_table = dest.quote_table_name table
71
71
  s_table = table.to_sym
72
+ order_column = order_column_for s_table
73
+ last_value = nil
72
74
 
73
75
  get_chunks(src, table).times_with_progress(table.rjust max_tbl_name_len) do |chunk_i|
74
76
  offset = chunk_i * CHUNK_SIZE
75
- result = src.exec_query select_query q_table, s_table, offset
77
+ result = src.exec_query select_query q_table, order_column, last_value, offset
76
78
  dest.execute insert_query q_table, s_table, transformers, result, offset
79
+
80
+ last_value = result.last[order_column] if result.any?
77
81
  end
78
82
  end
79
83
  end
@@ -93,18 +97,22 @@ module DatabaseSanitizer
93
97
  ins_query.string
94
98
  end
95
99
 
96
- def select_query q_table, s_table, offset
97
- "SELECT * FROM #{q_table} #{order_clause s_table} LIMIT #{CHUNK_SIZE} OFFSET #{offset}"
100
+ def select_query q_table, order_column, last_value, offset
101
+ query = "SELECT * FROM #{q_table} "
102
+ query << "WHERE #{order_column} > #{last_value} " if last_value.present?
103
+ query << "ORDER BY #{order_column} " if order_column.present?
104
+ query << "LIMIT #{CHUNK_SIZE} "
105
+ query << "OFFSET #{offset} " unless order_column.present?
106
+ query
98
107
  end
99
-
100
- def order_clause s_table
101
- order_sql = 'ORDER BY '
108
+
109
+ def order_column_for s_table
102
110
  src = Source.connection
103
111
  order_by = extract_order src.retrieve_table_comment s_table
104
112
  if order_by
105
- order_sql + src.quote_table_name(order_by)
113
+ src.quote_table_name(order_by)
106
114
  elsif src.column_exists? s_table, :id
107
- order_sql + 'id'
115
+ 'id'
108
116
  else
109
117
  nil
110
118
  end
@@ -1,3 +1,3 @@
1
1
  module DatabaseSanitizer
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
@@ -82,7 +82,7 @@ SQL
82
82
  end
83
83
  end
84
84
 
85
- describe '#order_clause' do
85
+ describe '#order_column_for' do
86
86
  context 'no order comment' do
87
87
  context 'and no id' do
88
88
  before do
@@ -90,13 +90,13 @@ SQL
90
90
  end
91
91
 
92
92
  it 'should not order' do
93
- expect(described_class.order_clause :test).to be_nil
93
+ expect(described_class.order_column_for :test).to be_nil
94
94
  end
95
95
  end
96
96
 
97
97
  context 'and id' do
98
98
  it 'should order by id' do
99
- expect(described_class.order_clause :test).to end_with('id')
99
+ expect(described_class.order_column_for :test).to eq('id')
100
100
  end
101
101
  end
102
102
  end
@@ -106,7 +106,7 @@ SQL
106
106
  before { DatabaseSanitizer::Source.connection.set_table_comment :test, 'order_by: field2' }
107
107
 
108
108
  it 'should order by comment' do
109
- expect(described_class.order_clause :test).to end_with(DatabaseSanitizer::Source.connection.quote_table_name 'field2')
109
+ expect(described_class.order_column_for :test).to eq(DatabaseSanitizer::Source.connection.quote_table_name 'field2')
110
110
  end
111
111
  end
112
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marton Somogyi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler