activerecord-import-uuid 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/activerecord-import/import.rb +9 -5
- data/lib/activerecord-import/version.rb +1 -1
- data/test/models/vendor.rb +2 -0
- data/test/schema/jdbcpostgresql_schema.rb +1 -0
- data/test/schema/postgis_schema.rb +1 -0
- data/test/schema/postgresql_schema.rb +9 -0
- data/test/support/postgresql/import_examples.rb +16 -0
- metadata +9 -1
@@ -347,12 +347,16 @@ class ActiveRecord::Base
|
|
347
347
|
if args.last.is_a?( Array ) && args.last.first.is_a?(ActiveRecord::Base)
|
348
348
|
if args.length == 2
|
349
349
|
models = args.last
|
350
|
-
column_names = args.first
|
350
|
+
column_names = args.first.dup
|
351
351
|
else
|
352
352
|
models = args.first
|
353
353
|
column_names = self.column_names.dup
|
354
354
|
end
|
355
355
|
|
356
|
+
if column_names.include?(primary_key) && columns_hash[primary_key].type == :uuid
|
357
|
+
column_names.delete(primary_key)
|
358
|
+
end
|
359
|
+
|
356
360
|
array_of_attributes = models.map do |model|
|
357
361
|
# this next line breaks sqlite.so with a segmentation fault
|
358
362
|
# if model.new_record? || options[:on_duplicate_key_update]
|
@@ -367,14 +371,14 @@ class ActiveRecord::Base
|
|
367
371
|
# supports 2-element array and array
|
368
372
|
elsif args.size == 2 && args.first.is_a?( Array ) && args.last.is_a?( Array )
|
369
373
|
column_names, array_of_attributes = args
|
374
|
+
|
375
|
+
# dup the passed args so we don't modify unintentionally
|
376
|
+
column_names = column_names.dup
|
370
377
|
array_of_attributes = array_of_attributes.map(&:dup)
|
371
378
|
else
|
372
379
|
raise ArgumentError, "Invalid arguments!"
|
373
380
|
end
|
374
381
|
|
375
|
-
# dup the passed in array so we don't modify it unintentionally
|
376
|
-
column_names = column_names.dup
|
377
|
-
|
378
382
|
# Force the primary key col into the insert if it's not
|
379
383
|
# on the list and we are using a sequence and stuff a nil
|
380
384
|
# value for it into each row so the sequencer will fire later
|
@@ -531,7 +535,7 @@ class ActiveRecord::Base
|
|
531
535
|
return if models.nil?
|
532
536
|
import_result.ids.each_with_index do |id, index|
|
533
537
|
model = models[index]
|
534
|
-
model.id = id
|
538
|
+
model.id = id
|
535
539
|
if model.respond_to?(:clear_changes_information) # Rails 4.0 and higher
|
536
540
|
model.clear_changes_information
|
537
541
|
else # Rails 3.2
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/postgresql_schema')
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/postgresql_schema')
|
@@ -58,6 +58,22 @@ def should_support_postgresql_import_functionality
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
describe "with a uuid primary key" do
|
63
|
+
let(:vendor) { Vendor.new(name: "foo") }
|
64
|
+
let(:vendors) { [vendor] }
|
65
|
+
|
66
|
+
it "creates records" do
|
67
|
+
assert_difference "Vendor.count", +1 do
|
68
|
+
Vendor.import vendors
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "assigns an id to the model objects" do
|
73
|
+
Vendor.import vendors
|
74
|
+
assert_not_nil vendor.id
|
75
|
+
end
|
76
|
+
end
|
61
77
|
end
|
62
78
|
|
63
79
|
def should_support_postgresql_upsert_functionality
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-import-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- test/models/question.rb
|
128
128
|
- test/models/rule.rb
|
129
129
|
- test/models/topic.rb
|
130
|
+
- test/models/vendor.rb
|
130
131
|
- test/models/widget.rb
|
131
132
|
- test/mysql2/import_test.rb
|
132
133
|
- test/mysql2_makara/import_test.rb
|
@@ -134,7 +135,10 @@ files:
|
|
134
135
|
- test/postgis/import_test.rb
|
135
136
|
- test/postgresql/import_test.rb
|
136
137
|
- test/schema/generic_schema.rb
|
138
|
+
- test/schema/jdbcpostgresql_schema.rb
|
137
139
|
- test/schema/mysql_schema.rb
|
140
|
+
- test/schema/postgis_schema.rb
|
141
|
+
- test/schema/postgresql_schema.rb
|
138
142
|
- test/schema/version.rb
|
139
143
|
- test/sqlite3/import_test.rb
|
140
144
|
- test/support/active_support/test_case_extensions.rb
|
@@ -200,6 +204,7 @@ test_files:
|
|
200
204
|
- test/models/question.rb
|
201
205
|
- test/models/rule.rb
|
202
206
|
- test/models/topic.rb
|
207
|
+
- test/models/vendor.rb
|
203
208
|
- test/models/widget.rb
|
204
209
|
- test/mysql2/import_test.rb
|
205
210
|
- test/mysql2_makara/import_test.rb
|
@@ -207,7 +212,10 @@ test_files:
|
|
207
212
|
- test/postgis/import_test.rb
|
208
213
|
- test/postgresql/import_test.rb
|
209
214
|
- test/schema/generic_schema.rb
|
215
|
+
- test/schema/jdbcpostgresql_schema.rb
|
210
216
|
- test/schema/mysql_schema.rb
|
217
|
+
- test/schema/postgis_schema.rb
|
218
|
+
- test/schema/postgresql_schema.rb
|
211
219
|
- test/schema/version.rb
|
212
220
|
- test/sqlite3/import_test.rb
|
213
221
|
- test/support/active_support/test_case_extensions.rb
|