activerecord-import 1.0.5 → 1.0.6
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/CHANGELOG.md +9 -0
- data/README.markdown +1 -1
- data/lib/activerecord-import/adapters/abstract_adapter.rb +1 -1
- data/lib/activerecord-import/adapters/mysql_adapter.rb +1 -0
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +1 -0
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-import/import.rb +9 -4
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +29 -0
- data/test/models/animal.rb +6 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bedb8323d872ae8ca6daebc691f82fedc918a3f2c01e7e354a8534854c06d80e
|
4
|
+
data.tar.gz: 2df3dfaef596b93d208854557700167a4a8e0e9bb151ff224e4a6255e374086f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c97ba946d5453394831959f384868812ca59833d1c694feccc19d68967d38e3501305fca11fcd39dec32ddc8c88d26982ea2f087d590e34a19da88ff7def1c9c
|
7
|
+
data.tar.gz: 0fcdc64e20ac0ee42584ab97f060e116f2542a353f0dc815a616adbe3810d6a343f8b021c0204adde9eb484aac5befc4e0b4699b1bbdfbddb2d486f8418d1839
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## Changes in 1.0.6
|
2
|
+
|
3
|
+
### Fixes
|
4
|
+
|
5
|
+
* Handle after_initialize callbacks. Thanks to @AhMohsen46 via \#691 and
|
6
|
+
\#692.
|
7
|
+
* Fix regression introduced in 1.0.4. Explicity allow adapters to
|
8
|
+
support on duplicate key update. Thanks to @dsobiera, @jkowens via \#698.
|
9
|
+
|
1
10
|
## Changes in 1.0.5
|
2
11
|
|
3
12
|
### Fixes
|
data/README.markdown
CHANGED
@@ -529,7 +529,7 @@ require 'activerecord-import'
|
|
529
529
|
### Load Path Setup
|
530
530
|
To understand how rubygems loads code you can reference the following:
|
531
531
|
|
532
|
-
http://guides.rubygems.org/patterns/#
|
532
|
+
http://guides.rubygems.org/patterns/#loading-code
|
533
533
|
|
534
534
|
And an example of how active_record dynamically load adapters:
|
535
535
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module ActiveRecord::Import::MysqlAdapter
|
2
2
|
include ActiveRecord::Import::ImportSupport
|
3
|
+
include ActiveRecord::Import::OnDuplicateKeyUpdateSupport
|
3
4
|
|
4
5
|
NO_MAX_PACKET = 0
|
5
6
|
QUERY_OVERHEAD = 8 # This was shown to be true for MySQL, but it's not clear where the overhead is from.
|
@@ -11,6 +11,12 @@ module ActiveRecord::Import #:nodoc:
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
module OnDuplicateKeyUpdateSupport #:nodoc:
|
15
|
+
def supports_on_duplicate_key_update? #:nodoc:
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
class MissingColumnError < StandardError
|
15
21
|
def initialize(name, index)
|
16
22
|
super "Missing column for value <#{name}> at index #{index}"
|
@@ -576,7 +582,7 @@ class ActiveRecord::Base
|
|
576
582
|
if respond_to?(:timestamp_attributes_for_update, true)
|
577
583
|
send(:timestamp_attributes_for_update).map(&:to_sym)
|
578
584
|
else
|
579
|
-
|
585
|
+
allocate.send(:timestamp_attributes_for_update_in_model)
|
580
586
|
end
|
581
587
|
end
|
582
588
|
|
@@ -697,8 +703,7 @@ class ActiveRecord::Base
|
|
697
703
|
# keep track of the instance and the position it is currently at. if this fails
|
698
704
|
# validation we'll use the index to remove it from the array_of_attributes
|
699
705
|
arr.each_with_index do |hsh, i|
|
700
|
-
model = new
|
701
|
-
hsh.each_pair { |k, v| model[k] = v }
|
706
|
+
model = new(hsh)
|
702
707
|
next if validator.valid_model?(model)
|
703
708
|
raise(ActiveRecord::RecordInvalid, model) if options[:raise_error]
|
704
709
|
array_of_attributes[i] = nil
|
@@ -995,7 +1000,7 @@ class ActiveRecord::Base
|
|
995
1000
|
timestamp_columns[:create] = timestamp_attributes_for_create_in_model
|
996
1001
|
timestamp_columns[:update] = timestamp_attributes_for_update_in_model
|
997
1002
|
else
|
998
|
-
instance =
|
1003
|
+
instance = allocate
|
999
1004
|
timestamp_columns[:create] = instance.send(:timestamp_attributes_for_create_in_model)
|
1000
1005
|
timestamp_columns[:update] = instance.send(:timestamp_attributes_for_update_in_model)
|
1001
1006
|
end
|
data/test/import_test.rb
CHANGED
@@ -900,4 +900,33 @@ describe "#import" do
|
|
900
900
|
end
|
901
901
|
end
|
902
902
|
end
|
903
|
+
describe "importing model with after_initialize callback" do
|
904
|
+
let(:columns) { %w(name size) }
|
905
|
+
let(:valid_values) { [%w("Deer", "Small"), %w("Monkey", "Medium")] }
|
906
|
+
let(:invalid_values) do
|
907
|
+
[
|
908
|
+
{ name: "giraffe", size: "Large" },
|
909
|
+
{ size: "Medium" } # name is missing
|
910
|
+
]
|
911
|
+
end
|
912
|
+
context "with validation checks turned off" do
|
913
|
+
it "should import valid data" do
|
914
|
+
Animal.import(columns, valid_values, validate: false)
|
915
|
+
assert_equal 2, Animal.count
|
916
|
+
end
|
917
|
+
it "should raise ArgumentError" do
|
918
|
+
assert_raise(ArgumentError) { Animal.import(invalid_values, validate: false) }
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
context "with validation checks turned on" do
|
923
|
+
it "should import valid data" do
|
924
|
+
Animal.import(columns, valid_values, validate: true)
|
925
|
+
assert_equal 2, Animal.count
|
926
|
+
end
|
927
|
+
it "should raise ArgumentError" do
|
928
|
+
assert_raise(ArgumentError) { Animal.import(invalid_values, validate: true) }
|
929
|
+
end
|
930
|
+
end
|
931
|
+
end
|
903
932
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- test/makara_postgis/import_test.rb
|
122
122
|
- test/models/account.rb
|
123
123
|
- test/models/alarm.rb
|
124
|
+
- test/models/animal.rb
|
124
125
|
- test/models/bike_maker.rb
|
125
126
|
- test/models/book.rb
|
126
127
|
- test/models/car.rb
|
@@ -170,7 +171,7 @@ homepage: http://github.com/zdennis/activerecord-import
|
|
170
171
|
licenses:
|
171
172
|
- MIT
|
172
173
|
metadata: {}
|
173
|
-
post_install_message:
|
174
|
+
post_install_message:
|
174
175
|
rdoc_options: []
|
175
176
|
require_paths:
|
176
177
|
- lib
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
189
|
rubygems_version: 3.0.6
|
189
|
-
signing_key:
|
190
|
+
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: Bulk insert extension for ActiveRecord
|
192
193
|
test_files:
|
@@ -211,6 +212,7 @@ test_files:
|
|
211
212
|
- test/makara_postgis/import_test.rb
|
212
213
|
- test/models/account.rb
|
213
214
|
- test/models/alarm.rb
|
215
|
+
- test/models/animal.rb
|
214
216
|
- test/models/bike_maker.rb
|
215
217
|
- test/models/book.rb
|
216
218
|
- test/models/car.rb
|