database_sanitizer 0.0.15 → 0.0.16
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 +4 -4
- data/lib/database_sanitizer.rb +16 -8
- data/lib/database_sanitizer/version.rb +1 -1
- data/spec/database_sanitizer_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77d9e46bfe3e7f9f5bd05c51eb1925384a0eb69d
|
4
|
+
data.tar.gz: 7ca1d69283a346ec4faecf93ea7c1e648c1a39ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0acd414b98a2100ec34b58520ac52e11927c8b4ba7981f6ab2ffec1ec85cea8c798d85913c7382a1ad9a17148086a87f3469097f1fe31daa22b9a8a855e77f0
|
7
|
+
data.tar.gz: 53c1293ab81f599e72688cdf94c15d6846d760c0cb11bd38dc2c91da89ac13d29e60f2d0b8d9adc1a069e1d0fc5a0838d56b104ef5a0a7744660bc37e39e0980
|
data/lib/database_sanitizer.rb
CHANGED
@@ -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,
|
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,
|
97
|
-
"SELECT * FROM #{q_table}
|
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
|
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
|
-
|
113
|
+
src.quote_table_name(order_by)
|
106
114
|
elsif src.column_exists? s_table, :id
|
107
|
-
|
115
|
+
'id'
|
108
116
|
else
|
109
117
|
nil
|
110
118
|
end
|
@@ -82,7 +82,7 @@ SQL
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe '#
|
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.
|
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.
|
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.
|
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.
|
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-
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|