activerecord-import 0.14.1 → 0.15.0
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 +17 -2
- data/gemfiles/4.2.gemfile +4 -0
- data/gemfiles/5.0.gemfile +1 -1
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +5 -4
- data/lib/activerecord-import/import.rb +6 -2
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +2 -1
- data/test/support/postgresql/import_examples.rb +36 -7
- 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: 7c1b3ac9675567f96311618bfcf008c344559183
|
4
|
+
data.tar.gz: 796d923d2db2f0317c832081e2ea336b9f933a7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17a0387cd93c752b91f8cee9bf0fa311463e927debf83141a759e277d5e632aa7f468fa0b36a082d54adad0596cae40f31002f699b6189c0b00ce1b072e666c9
|
7
|
+
data.tar.gz: 587d1a167feb65558bf10208404a23bc409c6a4f48e8dd64cc32e0e2af76e1f9b81247a17658c47de102d29a0b8b4619a021d1b78bde61aa00fa5403b38c2aaa
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
|
+
## Changes in 0.15.0
|
2
|
+
|
3
|
+
### New Features
|
4
|
+
|
5
|
+
* An ArgumentError is now raised if when no `conflict_target` or `conflict_name` is provided or can be determined when using the `on_duplicate_key_update` option for PostgreSQL. Thanks to @jkowens via \#290
|
6
|
+
* Support for Rails 5.0 final release for all except the JDBC driver which is not yet updated to support Rails 5.0
|
7
|
+
|
8
|
+
### Fixes
|
9
|
+
|
10
|
+
* activerecord-import no longer modifies a value array inside of the given values array when called with `import(columns, values)`. Thanks to @jkowens via \#291
|
11
|
+
|
12
|
+
### Misc
|
13
|
+
|
14
|
+
* `raise_error` is used to raise errors for ActiveRecord 5.0. Thanks to @couragecourag via \#294 `raise_record_invalid` has been
|
15
|
+
|
16
|
+
|
1
17
|
## Changes in 0.14.1
|
2
18
|
|
3
19
|
### Fixes
|
4
20
|
|
5
|
-
* JRuby/JDBCDriver with PostgreSQL will no longer raise a JDBCDriver error when using the :no_returning boolean option. Thanks to
|
21
|
+
* JRuby/JDBCDriver with PostgreSQL will no longer raise a JDBCDriver error when using the :no_returning boolean option. Thanks to @jkowens via \#287
|
6
22
|
|
7
23
|
## Changes in 0.14.0
|
8
24
|
|
@@ -26,7 +42,6 @@
|
|
26
42
|
* Code cleanup, removal of deprecated `alias_method_chain`. Thanks to @codeodor via \#271
|
27
43
|
|
28
44
|
|
29
|
-
|
30
45
|
## Changes in 0.13.0
|
31
46
|
|
32
47
|
### New Features
|
data/gemfiles/4.2.gemfile
CHANGED
data/gemfiles/5.0.gemfile
CHANGED
@@ -113,15 +113,16 @@ module ActiveRecord::Import::PostgreSQLAdapter
|
|
113
113
|
def sql_for_conflict_target( args = {} )
|
114
114
|
constraint_name = args[:constraint_name]
|
115
115
|
conflict_target = args[:conflict_target]
|
116
|
-
if constraint_name
|
116
|
+
if constraint_name.present?
|
117
117
|
"ON CONSTRAINT #{constraint_name} "
|
118
|
-
elsif conflict_target
|
119
|
-
'(' << Array( conflict_target ).join( ', ' ) << ') '
|
118
|
+
elsif conflict_target.present?
|
119
|
+
'(' << Array( conflict_target ).reject( &:empty? ).join( ', ' ) << ') '
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
def sql_for_default_conflict_target( table_name )
|
124
|
-
|
124
|
+
conflict_target = primary_key( table_name )
|
125
|
+
"(#{conflict_target}) " if conflict_target
|
125
126
|
end
|
126
127
|
|
127
128
|
# Return true if the statement is a duplicate key record error
|
@@ -367,13 +367,13 @@ class ActiveRecord::Base
|
|
367
367
|
# supports 2-element array and array
|
368
368
|
elsif args.size == 2 && args.first.is_a?( Array ) && args.last.is_a?( Array )
|
369
369
|
column_names, array_of_attributes = args
|
370
|
+
array_of_attributes = array_of_attributes.map(&:dup)
|
370
371
|
else
|
371
372
|
raise ArgumentError, "Invalid arguments!"
|
372
373
|
end
|
373
374
|
|
374
375
|
# dup the passed in array so we don't modify it unintentionally
|
375
376
|
column_names = column_names.dup
|
376
|
-
array_of_attributes = array_of_attributes.dup
|
377
377
|
|
378
378
|
# Force the primary key col into the insert if it's not
|
379
379
|
# on the list and we are using a sequence and stuff a nil
|
@@ -394,7 +394,11 @@ class ActiveRecord::Base
|
|
394
394
|
models.each_with_index do |model, i|
|
395
395
|
model = model.dup if options[:recursive]
|
396
396
|
next if model.valid?(options[:validate_with_context])
|
397
|
-
model.
|
397
|
+
if options[:raise_error] && model.respond_to?(:raise_validation_error, true) # Rails 5.0 and higher
|
398
|
+
model.send(:raise_validation_error)
|
399
|
+
elsif options[:raise_error] # Rails 3.2, 4.0, 4.1 and 4.2
|
400
|
+
model.send(:raise_record_invalid)
|
401
|
+
end
|
398
402
|
array_of_attributes[i] = nil
|
399
403
|
failed << model
|
400
404
|
end
|
data/test/import_test.rb
CHANGED
@@ -29,7 +29,8 @@ describe "#import" do
|
|
29
29
|
|
30
30
|
it "should not modify the passed in values array" do
|
31
31
|
assert_nothing_raised do
|
32
|
-
|
32
|
+
record = %w(foo bar).freeze
|
33
|
+
values = [record].freeze
|
33
34
|
Topic.import %w(title author_name), values
|
34
35
|
end
|
35
36
|
end
|
@@ -170,27 +170,56 @@ def should_support_postgresql_upsert_functionality
|
|
170
170
|
should_update_fields_mentioned
|
171
171
|
end
|
172
172
|
|
173
|
-
context "
|
173
|
+
context "default to the primary key" do
|
174
174
|
let(:columns) { %w( id title author_name author_email_address parent_id ) }
|
175
175
|
let(:values) { [[100, "Book", "John Doe", "john@doe.com", 17]] }
|
176
176
|
let(:updated_values) { [[100, "Book - 2nd Edition", "Author Should Not Change", "johndoe@example.com", 57]] }
|
177
|
-
|
178
|
-
macro(:perform_import) do |*opts|
|
179
|
-
Topic.import columns, updated_values, opts.extract_options!.merge(on_duplicate_key_update: { columns: update_columns }, validate: false)
|
180
|
-
end
|
177
|
+
let(:update_columns) { [:title, :author_email_address, :parent_id] }
|
181
178
|
|
182
179
|
setup do
|
183
180
|
Topic.import columns, values, validate: false
|
184
181
|
@topic = Topic.find 100
|
185
182
|
end
|
186
183
|
|
187
|
-
context "
|
188
|
-
|
184
|
+
context "with no :conflict_target or :constraint_name" do
|
185
|
+
macro(:perform_import) do |*opts|
|
186
|
+
Topic.import columns, updated_values, opts.extract_options!.merge(on_duplicate_key_update: { columns: update_columns }, validate: false)
|
187
|
+
end
|
188
|
+
|
189
|
+
should_support_on_duplicate_key_update
|
190
|
+
should_update_fields_mentioned
|
191
|
+
end
|
192
|
+
|
193
|
+
context "with empty value for :conflict_target" do
|
194
|
+
macro(:perform_import) do |*opts|
|
195
|
+
Topic.import columns, updated_values, opts.extract_options!.merge(on_duplicate_key_update: { conflict_target: [], columns: update_columns }, validate: false)
|
196
|
+
end
|
197
|
+
|
198
|
+
should_support_on_duplicate_key_update
|
199
|
+
should_update_fields_mentioned
|
200
|
+
end
|
201
|
+
|
202
|
+
context "with empty value for :constraint_name" do
|
203
|
+
macro(:perform_import) do |*opts|
|
204
|
+
Topic.import columns, updated_values, opts.extract_options!.merge(on_duplicate_key_update: { constraint_name: '', columns: update_columns }, validate: false)
|
205
|
+
end
|
206
|
+
|
189
207
|
should_support_on_duplicate_key_update
|
190
208
|
should_update_fields_mentioned
|
191
209
|
end
|
192
210
|
end
|
193
211
|
|
212
|
+
context "with no :conflict_target or :constraint_name" do
|
213
|
+
context "with no primary key" do
|
214
|
+
it "raises ArgumentError" do
|
215
|
+
error = assert_raises ArgumentError do
|
216
|
+
Widget.import Build(1, :widgets), on_duplicate_key_update: [:data], validate: false
|
217
|
+
end
|
218
|
+
assert_match(/Expected :conflict_target or :constraint_name to be specified/, error.message)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
194
223
|
context "with no :columns" do
|
195
224
|
let(:columns) { %w( id title author_name author_email_address ) }
|
196
225
|
let(:values) { [[100, "Book", "John Doe", "john@doe.com"]] }
|
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: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|