idata 0.1.21 → 0.1.22

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ivalidate +37 -1
  3. data/lib/idata/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffabe9c30976ac3d4d15cb5ace2e561bd072ee7d
4
- data.tar.gz: 83561c0933cbb0bebb4640088e3271a939920682
3
+ metadata.gz: 6e01ecdfe5b0d94ddb4f503305f73177fcbeabc4
4
+ data.tar.gz: 0a053ddd16efb8b99f91a967a99a448dcd878e64
5
5
  SHA512:
6
- metadata.gz: bd4baaa165ccb22bc458d2a7defd96a4d1069be6f88fce2bb7310ecd26ade3ae7e6610c5cc468a0e43decfda2041d6bb217525457cf58646229e6da83414ea66
7
- data.tar.gz: f5dc5ae7dae7c65de2415ca589f01445748250c500c680aeb8ef81dd204165d4f0e7ac4040d3d1f021905e88e91c4bdf3296042de14b631fc6da3794cb448f87
6
+ metadata.gz: 334419ae0fbbfeebf3b3db0b91381007d78e9f4fb162346a6edb7755b0fe57aca5dd059e6cc74ed9d16241087ed9afe1f4c6b8e3d11c05a55faaa6f47a51ee9c
7
+ data.tar.gz: f4468fde70bb3ac1ff0218bc6d7d1392e23f3d67837358667460ebd0a54408adc74ee759a4a356a0133fdf9a022dfd9df0ab658b79443bddcacea4b76586d9f1
data/bin/ivalidate CHANGED
@@ -24,7 +24,8 @@ $options = {
24
24
  :not_match => [],
25
25
  :cross_reference => [],
26
26
  :query => [],
27
- :rquery => []
27
+ :rquery => [],
28
+ :unique_by => []
28
29
  }
29
30
  parser = OptionParser.new("", 24) do |opts|
30
31
  opts.banner = "\nProgram: Data Validator\nAuthor: MCKI\n\n"
@@ -32,6 +33,10 @@ parser = OptionParser.new("", 24) do |opts|
32
33
  opts.on("--unique FIELD", "Check if FIELD is unique") do |v|
33
34
  $options[:unique] << v
34
35
  end
36
+
37
+ opts.on("--unique-by FIELD1|FIELD2", "Check if FIELD1 is unique within the scope of FIELD2") do |v|
38
+ $options[:unique_by] << v
39
+ end
35
40
 
36
41
  opts.on("--not-null FIELD", "Check if FIELD is not null or empty") do |v|
37
42
  $options[:not_null] << v
@@ -201,6 +206,37 @@ $options[:unique].each do |field|
201
206
  end
202
207
  end
203
208
 
209
+ # --------------------------------------------------------------------
210
+ # Check unique within scope
211
+ # --------------------------------------------------------------------
212
+ $options[:unique_by].each do |fields|
213
+ begin
214
+ fields = fields.split(/\s*\|\s*/)
215
+
216
+ raise "input must be in field1|field2 format" if fields.count != 2
217
+
218
+ f1 = fields.first
219
+ f2 = fields.last
220
+
221
+ puts "Checking uniqueness: #{f1} | #{f2}"
222
+
223
+ 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 #{f2} IN
226
+ (
227
+ SELECT #{f2} FROM #{$options[:table]}
228
+ GROUP BY #{f2}
229
+ HAVING COUNT(distinct #{f1}) > 1
230
+ ) AND #{f1} IS NOT NULL AND length(trim(#{f1})) <> 0 AND #{f2} IS NOT NULL AND length(trim(#{f2})) <> 0;
231
+ eos
232
+
233
+ ActiveRecord::Base.connection.execute(uniq_sql)
234
+ rescue Exception => ex
235
+ puts " --> *** ERROR ***: #{ex.message.split("\n").first }"
236
+ end
237
+ end
238
+
239
+
204
240
  # --------------------------------------------------------------------
205
241
  # Check not-null field
206
242
  # --------------------------------------------------------------------
data/lib/idata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Idata
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
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.21
4
+ version: 0.1.22
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-20 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler