activerecord_csv_importer 0.1.6 → 0.1.7

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: 51557f583780074a8a0718c67716819019fdf6a4
4
- data.tar.gz: b8189aa2383e03520fea9135a26865a045f91ed3
3
+ metadata.gz: edb1f1d0c16e3d3a8554d947c8ff2f19e6d4e109
4
+ data.tar.gz: 6333c0ee24f56784fd42e8cc8fb668f49218f900
5
5
  SHA512:
6
- metadata.gz: 6f08ead55c0b4e07c74ea76d19684406b5a7cde9c859cc3d0e1726844609357a243c9c74745495c928897316ea856badda6edef721bcfd9a587185843c249b9e
7
- data.tar.gz: 7ef1d416e306142fd613d1b274841c2e555ebf6bfc3075119e6432eccd8916c3a2e9fc461a95ade5856afd145e76a4bcdd547b4bf1f5a161b3d5e7f504b7bba6
6
+ metadata.gz: 243f72e4566324706c19a8aeee726dfed611164a513f4da861d6cf6efa666daf52e84fadfbf3974f6e223758d9268a37fed92985a219e05027361a122bca6eeb
7
+ data.tar.gz: 9a225ecbf836650498b221e775b76354b2ff6efe775343e70eea96691d19850e7922cd9cd60d24a645c3c058143d8398ff512e8c05fad66e5b7763f5e0be3455
@@ -30,13 +30,23 @@ module ActiveRecordCSVImporter
30
30
 
31
31
  def persist_rows!
32
32
  rows.in_groups_of(config.batch_size, false) do |set|
33
- response = import_rows(set)
33
+ response = import_rows(dedupe(set))
34
34
 
35
35
  add_to_report(response, set)
36
36
  config.each_batch_blocks.each { |block| block.call(report) }
37
37
  end
38
38
  end
39
39
 
40
+ # prevent PG::CardinalityViolation
41
+ def dedupe(set)
42
+ conflict_target = config.on_duplicate_key.dig(:on_duplicate_key_update, :conflict_target)
43
+ return set unless conflict_target
44
+
45
+ column_name = conflict_target.last.to_s
46
+ i = header.columns.index { |c| c.name == column_name }
47
+ set.uniq { |s| s[i] }
48
+ end
49
+
40
50
  def import_rows(set)
41
51
  config.model.import(header.column_definition_names.dup, set, config.on_duplicate_key)
42
52
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordCSVImporter
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_csv_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zulfiqar Ali
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-15 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus