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 +4 -4
- data/lib/activerecord_csv_importer/runner.rb +11 -1
- data/lib/activerecord_csv_importer/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: edb1f1d0c16e3d3a8554d947c8ff2f19e6d4e109
|
4
|
+
data.tar.gz: 6333c0ee24f56784fd42e8cc8fb668f49218f900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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-
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|