abstract_importer 1.5.3 → 1.5.4

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: 827772f8267bf04e58720c203493a53c9c45f4ce
4
- data.tar.gz: 6c0b1d51976d1948edf91f77ba11b975ef2bb7f9
3
+ metadata.gz: ddf30730dc02843631c647c8f342623ebc46a87e
4
+ data.tar.gz: 571852378a10de0e78df4952ad9241c0af25092d
5
5
  SHA512:
6
- metadata.gz: cf95cb9bdc64b7f0b318e2ff811eddeecf579a9fbc7255eb107c2b894306d62d996de088ffe239b6d5e1fc1705d58f06b0fc238e2baf29145938f1569e68e2b9
7
- data.tar.gz: c07595116a66d93ce567bbf4d6209fd0dfc8911d697899ffee5afab679efe6c9b214f7bfc432ecfa9ea8da141aa981d8c69ae1fc4101e9b78ef7aaecdbaf8abb
6
+ metadata.gz: ac466e7b1f05a6074ae42d8e9dc188b641f8210caf95277e54830a4dd05a0c73a794392a8ee77dca07c5c600fb4ff47b9d5acc54f41c5f3c677c396db788ead9
7
+ data.tar.gz: 3283e7ad8cb0b45d5364d917efdc28565755114f099113000b358411c1ec25e5c5fe3e3a75cf78b483b825bcf19cf6f1d4f655aca1ba8aaec5fa7420c434da45
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "activerecord", ">= 5.0"
21
21
  spec.add_dependency "activesupport", ">= 5.0"
22
- spec.add_dependency "activerecord-insert_many", ">= 0.4.1"
22
+ spec.add_dependency "activerecord-insert_many", ">= 0.4.3"
23
23
  spec.add_dependency "progressbar"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -206,7 +206,7 @@ module AbstractImporter
206
206
  protected
207
207
 
208
208
  def scope_for(collection_name)
209
- parent.public_send(collection_name)
209
+ parent.public_send(collection_name).unscope(:order)
210
210
  end
211
211
 
212
212
  private
@@ -10,6 +10,7 @@ module AbstractImporter
10
10
  @batch = []
11
11
  @batch_size = options.fetch(:batch_size, 250)
12
12
  @insert_options = options.slice(:on_conflict)
13
+ @insert_options.merge!(returning: [:legacy_id, :id]) if remap_ids?
13
14
  end
14
15
 
15
16
 
@@ -43,8 +44,6 @@ module AbstractImporter
43
44
 
44
45
  insert_batch(@batch)
45
46
 
46
- id_map_record_batch(@batch) if remap_ids?
47
-
48
47
  summary.created += @batch.length
49
48
  reporter.batch_inserted(@batch.length)
50
49
 
@@ -53,7 +52,8 @@ module AbstractImporter
53
52
 
54
53
 
55
54
  def insert_batch(batch)
56
- collection.scope.insert_many(batch, @insert_options)
55
+ result = collection.scope.insert_many(batch, @insert_options)
56
+ add_batch_to_id_map(result) if remap_ids?
57
57
  end
58
58
 
59
59
 
@@ -65,10 +65,11 @@ module AbstractImporter
65
65
  end
66
66
 
67
67
 
68
- def id_map_record_batch(batch)
69
- return if generate_id
70
- id_map.merge! collection.table_name,
71
- collection.scope.where(legacy_id: @batch.map { |hash| hash[:legacy_id] })
68
+ def add_batch_to_id_map(result)
69
+ map = result.each_with_object({}) do |attrs, map|
70
+ map[attrs.fetch("legacy_id")] = attrs.fetch("id")
71
+ end
72
+ id_map.merge! collection.table_name, map
72
73
  end
73
74
 
74
75
 
@@ -1,3 +1,3 @@
1
1
  module AbstractImporter
2
- VERSION = "1.5.3"
2
+ VERSION = "1.5.4"
3
3
  end
@@ -17,7 +17,7 @@ class InsertStrategyTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  should "import the records in batches" do
20
- mock.proxy(Student).insert_many(satisfy { |arg| arg.length == 3 }, {})
20
+ mock.proxy(Student).insert_many(satisfy { |arg| arg.length == 3 }, anything)
21
21
  import!
22
22
  assert_equal [456, 457, 458], account.students.pluck(:legacy_id)
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstract_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-06 00:00:00.000000000 Z
11
+ date: 2018-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.4.1
47
+ version: 0.4.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.4.1
54
+ version: 0.4.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: progressbar
57
57
  requirement: !ruby/object:Gem::Requirement