idata 0.1.20 → 0.1.21
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 +121 -90
- 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: ffabe9c30976ac3d4d15cb5ace2e561bd072ee7d
|
4
|
+
data.tar.gz: 83561c0933cbb0bebb4640088e3271a939920682
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd4baaa165ccb22bc458d2a7defd96a4d1069be6f88fce2bb7310ecd26ade3ae7e6610c5cc468a0e43decfda2041d6bb217525457cf58646229e6da83414ea66
|
7
|
+
data.tar.gz: f5dc5ae7dae7c65de2415ca589f01445748250c500c680aeb8ef81dd204165d4f0e7ac4040d3d1f021905e88e91c4bdf3296042de14b631fc6da3794cb448f87
|
data/bin/ivalidate
CHANGED
@@ -159,6 +159,9 @@ ActiveRecord::Base.establish_connection(
|
|
159
159
|
'timeout' => 15000
|
160
160
|
)
|
161
161
|
|
162
|
+
puts "\nValidating #{$options[:table]}"
|
163
|
+
puts "------------------------------------------"
|
164
|
+
|
162
165
|
# --------------------------------------------------------------------
|
163
166
|
# Preliminary check
|
164
167
|
# Add column errors if not yet exists
|
@@ -181,135 +184,163 @@ ActiveRecord::Base.connection.execute(pre_sql)
|
|
181
184
|
# Check unique field
|
182
185
|
# --------------------------------------------------------------------
|
183
186
|
$options[:unique].each do |field|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
187
|
+
begin
|
188
|
+
puts "Checking uniqueness: #{field}"
|
189
|
+
|
190
|
+
uniq_sql = <<-eos
|
191
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} is not unique', ' || '), ' || ')
|
192
|
+
WHERE #{field} IN (
|
193
|
+
SELECT #{field} FROM #{$options[:table]} GROUP BY #{field}
|
194
|
+
HAVING count(*) > 1
|
195
|
+
) AND #{field} IS NOT NULL AND length(trim(#{field})) <> 0;
|
196
|
+
eos
|
197
|
+
|
198
|
+
ActiveRecord::Base.connection.execute(uniq_sql)
|
199
|
+
rescue Exception => ex
|
200
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
201
|
+
end
|
195
202
|
end
|
196
203
|
|
197
204
|
# --------------------------------------------------------------------
|
198
205
|
# Check not-null field
|
199
206
|
# --------------------------------------------------------------------
|
200
207
|
$options[:not_null].each do |field|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
208
|
+
begin
|
209
|
+
puts "Checking NULL: #{field}"
|
210
|
+
|
211
|
+
not_null_sql = <<-eos
|
212
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} is null', ' || '), ' || ')
|
213
|
+
WHERE #{field} IS NULL OR length(trim(#{field})) = 0;
|
214
|
+
eos
|
215
|
+
|
216
|
+
ActiveRecord::Base.connection.execute(not_null_sql)
|
217
|
+
rescue Exception => ex
|
218
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
219
|
+
end
|
209
220
|
end
|
210
221
|
|
211
222
|
# --------------------------------------------------------------------
|
212
223
|
# Check field satisfying --match=FIELD/REGEXP/
|
213
224
|
# --------------------------------------------------------------------
|
214
225
|
$options[:match].each do |value|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
226
|
+
begin
|
227
|
+
field = value[/^[^\/]+/]
|
228
|
+
regexp = value[/(?<=\/).*(?=\/)/]
|
229
|
+
puts "Checking REGEXP matching: #{field} ~ #{regexp}"
|
230
|
+
|
231
|
+
match_sql = <<-eos
|
232
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} does not match [#{regexp.gsub("'", "''")}]', ' || '), ' || ')
|
233
|
+
WHERE #{field} IS NOT NULL AND length(trim(#{field})) <> 0 AND #{field} !~ '#{regexp}';
|
234
|
+
eos
|
235
|
+
|
236
|
+
ActiveRecord::Base.connection.execute(match_sql)
|
237
|
+
rescue Exception => ex
|
238
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
239
|
+
end
|
225
240
|
end
|
226
241
|
|
227
242
|
# --------------------------------------------------------------------
|
228
243
|
# Check field satisfying --not-match=FIELD/REGEXP/
|
229
244
|
# --------------------------------------------------------------------
|
230
245
|
$options[:not_match].each do |value|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
246
|
+
begin
|
247
|
+
field = value[/^[^\/]+/]
|
248
|
+
regexp = value[/(?<=\/).*(?=\/)/]
|
249
|
+
puts "Checking REGEXP not matching: #{regexp}"
|
250
|
+
|
251
|
+
not_match_sql = <<-eos
|
252
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} does match [#{regexp.gsub("'", "''")}]', ' || '), ' || ')
|
253
|
+
WHERE #{field} IS NOT NULL AND length(trim(#{field})) <> 0 AND #{field} ~ '#{regexp}';
|
254
|
+
eos
|
255
|
+
|
256
|
+
ActiveRecord::Base.connection.execute(not_match_sql)
|
257
|
+
rescue Exception => ex
|
258
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
259
|
+
end
|
241
260
|
end
|
242
261
|
|
243
262
|
# --------------------------------------------------------------------
|
244
263
|
# Check field satisfying --cross-reference
|
245
264
|
# --------------------------------------------------------------------
|
246
265
|
$options[:cross_reference].each do |value|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
266
|
+
begin
|
267
|
+
values = value.split(/[|\.]/)
|
268
|
+
|
269
|
+
if values.size != 3
|
270
|
+
raise "Error: Wrong argument for --cross-reference switch"
|
271
|
+
exit(0)
|
272
|
+
end
|
273
|
+
|
274
|
+
field = values[0]
|
275
|
+
ref_table = values[1]
|
276
|
+
ref_field = values[2]
|
277
|
+
|
278
|
+
puts "Checking data integrity: #{value}"
|
279
|
+
|
280
|
+
# @todo: poor performance here, think of a better SQL!!!
|
281
|
+
ref_sql = <<-eos
|
282
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} does not reference #{values[1]}.#{values[2]}', ' || '), ' || ')
|
283
|
+
WHERE #{field} IN (
|
284
|
+
SELECT origin.#{field} from #{$options[:table]} origin LEFT JOIN #{ref_table} target
|
285
|
+
on origin.#{field} = target.#{ref_field}
|
286
|
+
where target.#{ref_field} is null
|
287
|
+
) AND #{field} IS NOT NULL AND length(trim(#{field})) <> 0;
|
288
|
+
eos
|
289
|
+
|
290
|
+
ActiveRecord::Base.connection.execute(ref_sql)
|
291
|
+
rescue Exception => ex
|
292
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
252
293
|
end
|
253
|
-
|
254
|
-
field = values[0]
|
255
|
-
ref_table = values[1]
|
256
|
-
ref_field = values[2]
|
257
|
-
|
258
|
-
puts "Checking data integrity: #{value}"
|
259
|
-
|
260
|
-
# @todo: poor performance here, think of a better SQL!!!
|
261
|
-
ref_sql = <<-eos
|
262
|
-
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{field} does not reference #{values[1]}.#{values[2]}', ' || '), ' || ')
|
263
|
-
WHERE #{field} IN (
|
264
|
-
SELECT origin.#{field} from #{$options[:table]} origin LEFT JOIN #{ref_table} target
|
265
|
-
on origin.#{field} = target.#{ref_field}
|
266
|
-
where target.#{ref_field} is null
|
267
|
-
) AND #{field} IS NOT NULL AND length(trim(#{field})) <> 0;
|
268
|
-
eos
|
269
|
-
|
270
|
-
ActiveRecord::Base.connection.execute(ref_sql)
|
271
294
|
end
|
272
295
|
|
273
296
|
# --------------------------------------------------------------------
|
274
297
|
# Custom validation
|
275
298
|
# --------------------------------------------------------------------
|
276
299
|
$options[:query].each do |query|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
300
|
+
begin
|
301
|
+
if query.split("--").count > 1
|
302
|
+
message = query.split("--").last.strip
|
303
|
+
else
|
304
|
+
message = "custom-validation"
|
305
|
+
end
|
306
|
+
|
307
|
+
puts "Checking with custom query: #{query[0..50]}#{query.size > 51 ? "..." : "" }"
|
308
|
+
|
309
|
+
# @todo: poor performance here, think of a better SQL!!!
|
310
|
+
custom_sql = <<-eos
|
311
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{message}', ' || '), ' || ')
|
312
|
+
WHERE NOT #{query}
|
313
|
+
eos
|
314
|
+
|
315
|
+
ActiveRecord::Base.connection.execute(custom_sql)
|
316
|
+
rescue Exception => ex
|
317
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
281
318
|
end
|
282
|
-
|
283
|
-
puts "Checking with custom query: #{query[0..50]}#{query.size > 51 ? "..." : "" }"
|
284
|
-
|
285
|
-
# @todo: poor performance here, think of a better SQL!!!
|
286
|
-
custom_sql = <<-eos
|
287
|
-
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{message}', ' || '), ' || ')
|
288
|
-
WHERE NOT #{query}
|
289
|
-
eos
|
290
|
-
|
291
|
-
ActiveRecord::Base.connection.execute(custom_sql)
|
292
319
|
end
|
293
320
|
|
294
321
|
# --------------------------------------------------------------------
|
295
322
|
# Custom validation
|
296
323
|
# --------------------------------------------------------------------
|
297
324
|
$options[:rquery].each do |query|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
325
|
+
begin
|
326
|
+
if query.split("--").count > 1
|
327
|
+
message = query.split("--").last.strip
|
328
|
+
else
|
329
|
+
message = "custom-validation"
|
330
|
+
end
|
331
|
+
|
332
|
+
puts "Checking with custom query: #{query[0..50]}#{query.size > 51 ? "..." : "" }"
|
333
|
+
|
334
|
+
# @todo: poor performance here, think of a better SQL!!!
|
335
|
+
custom_sql = <<-eos
|
336
|
+
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{message}', ' || '), ' || ')
|
337
|
+
WHERE #{query}
|
338
|
+
eos
|
339
|
+
|
340
|
+
ActiveRecord::Base.connection.execute(custom_sql)
|
341
|
+
rescue Exception => ex
|
342
|
+
puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
|
302
343
|
end
|
303
|
-
|
304
|
-
puts "Checking with custom query: #{query[0..50]}#{query.size > 51 ? "..." : "" }"
|
305
|
-
|
306
|
-
# @todo: poor performance here, think of a better SQL!!!
|
307
|
-
custom_sql = <<-eos
|
308
|
-
UPDATE #{$options[:table]} SET #{$options[:log_to]} = array_to_string(string_to_array(#{$options[:log_to]}, ' || ') || string_to_array('#{message}', ' || '), ' || ')
|
309
|
-
WHERE #{query}
|
310
|
-
eos
|
311
|
-
|
312
|
-
ActiveRecord::Base.connection.execute(custom_sql)
|
313
344
|
end
|
314
345
|
|
315
346
|
|
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.21
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|