idata 0.1.22 → 0.1.23
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/bin/ivalidate +27 -15
- data/lib/idata/version.rb +1 -1
- 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: f09fd4a5e2e638192e76b3ca2b703a78a2c8f53b
|
4
|
+
data.tar.gz: c23665e7c90d463a7b9df4fec2d1ef64c794ea9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 548ecde59f31bdc4afc5eb3bf674ffc858c19c1bc78f36f42a60a4e07d80e9cc103965fec1353718fba8254222f50dc4e363aa5aa811da47e9471b78f7e29ebe
|
7
|
+
data.tar.gz: 24f64401382182e5fb549d962ca7e9bac9ea403ff7ce447b0d353b5ccfe41f88229c6aff54a98ff12212b6d137c7dcba1b134e16838984b9966064585d4957ef
|
data/bin/ivalidate
CHANGED
@@ -25,7 +25,7 @@ $options = {
|
|
25
25
|
:cross_reference => [],
|
26
26
|
:query => [],
|
27
27
|
:rquery => [],
|
28
|
-
:
|
28
|
+
:consistent_by => []
|
29
29
|
}
|
30
30
|
parser = OptionParser.new("", 24) do |opts|
|
31
31
|
opts.banner = "\nProgram: Data Validator\nAuthor: MCKI\n\n"
|
@@ -34,10 +34,10 @@ parser = OptionParser.new("", 24) do |opts|
|
|
34
34
|
$options[:unique] << v
|
35
35
|
end
|
36
36
|
|
37
|
-
opts.on("--
|
38
|
-
$options[:
|
37
|
+
opts.on("--consistent-by F1|F2,F3,F4...", "") do |v|
|
38
|
+
$options[:consistent_by] << v
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
opts.on("--not-null FIELD", "Check if FIELD is not null or empty") do |v|
|
42
42
|
$options[:not_null] << v
|
43
43
|
end
|
@@ -164,6 +164,18 @@ ActiveRecord::Base.establish_connection(
|
|
164
164
|
'timeout' => 15000
|
165
165
|
)
|
166
166
|
|
167
|
+
class String
|
168
|
+
def not_null_sql
|
169
|
+
a = self.split(/\s*,\s*/)
|
170
|
+
sql = a.map{|s|
|
171
|
+
"#{s} IS NOT NULL AND length(trim(#{s}::text)) <> 0"
|
172
|
+
}.join(" AND ")
|
173
|
+
|
174
|
+
"(#{sql})"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
|
167
179
|
puts "\nValidating #{$options[:table]}"
|
168
180
|
puts "------------------------------------------"
|
169
181
|
|
@@ -193,11 +205,11 @@ $options[:unique].each do |field|
|
|
193
205
|
puts "Checking uniqueness: #{field}"
|
194
206
|
|
195
207
|
uniq_sql = <<-eos
|
196
|
-
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} is not unique', ' || '), ' || ')
|
197
|
-
WHERE
|
198
|
-
SELECT
|
208
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('[#{field}] is not unique', ' || '), ' || ')
|
209
|
+
WHERE id IN (
|
210
|
+
SELECT unnest(array_agg(id)) FROM #{$options[:table]} GROUP BY #{field}
|
199
211
|
HAVING count(*) > 1
|
200
|
-
) AND #{field}
|
212
|
+
) AND #{field.not_null_sql};
|
201
213
|
eos
|
202
214
|
|
203
215
|
ActiveRecord::Base.connection.execute(uniq_sql)
|
@@ -207,9 +219,9 @@ $options[:unique].each do |field|
|
|
207
219
|
end
|
208
220
|
|
209
221
|
# --------------------------------------------------------------------
|
210
|
-
# Check
|
222
|
+
# Check consitent by scope
|
211
223
|
# --------------------------------------------------------------------
|
212
|
-
$options[:
|
224
|
+
$options[:consistent_by].each do |fields|
|
213
225
|
begin
|
214
226
|
fields = fields.split(/\s*\|\s*/)
|
215
227
|
|
@@ -221,13 +233,14 @@ $options[:unique_by].each do |fields|
|
|
221
233
|
puts "Checking uniqueness: #{f1} | #{f2}"
|
222
234
|
|
223
235
|
uniq_sql = <<-eos
|
224
|
-
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('same #{f2} but with different #{f1}', ' || '), ' || ')
|
225
|
-
WHERE
|
236
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('same [#{f2}] but with different #{f1}', ' || '), ' || ')
|
237
|
+
WHERE id IN
|
226
238
|
(
|
227
|
-
SELECT
|
239
|
+
SELECT unnest(array_agg(id)) FROM #{$options[:table]}
|
240
|
+
WHERE #{f1.not_null_sql} AND #{f2.not_null_sql}
|
228
241
|
GROUP BY #{f2}
|
229
242
|
HAVING COUNT(distinct #{f1}) > 1
|
230
|
-
)
|
243
|
+
);
|
231
244
|
eos
|
232
245
|
|
233
246
|
ActiveRecord::Base.connection.execute(uniq_sql)
|
@@ -236,7 +249,6 @@ $options[:unique_by].each do |fields|
|
|
236
249
|
end
|
237
250
|
end
|
238
251
|
|
239
|
-
|
240
252
|
# --------------------------------------------------------------------
|
241
253
|
# Check not-null field
|
242
254
|
# --------------------------------------------------------------------
|
data/lib/idata/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nghi Pham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|