activerecord-import 0.17.1 → 0.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/CHANGELOG.md +13 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +0 -6
- data/lib/activerecord-import/adapters/mysql_adapter.rb +2 -2
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +1 -1
- data/lib/activerecord-import/import.rb +5 -3
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +8 -0
- data/test/models/car.rb +3 -0
- data/test/schema/generic_schema.rb +7 -0
- data/test/schema/postgresql_schema.rb +2 -0
- data/test/support/factories.rb +5 -0
- data/test/support/postgresql/import_examples.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5482a79b112f9689eee0261baa906028abd8575f
|
4
|
+
data.tar.gz: 2f3e76132e6110a5ed17db800f173b5291ddfe8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509fe999b0343506f4b1263909d24079394d82d8d3aa16fa5210f35a88b92f40954141949ee7a5f979a81f6105838f0471c5c8cdcfa75a30a5abd38fc96cd1f8
|
7
|
+
data.tar.gz: 517d7de4678ddf9361647f18d08d95c2256e244ae3e6241413abde6b83992e62f4640279c42abdea8bbc710855800840fd2bf941bdca1b447693f2d82cbaa987
|
data/.travis.yml
CHANGED
@@ -16,11 +16,10 @@ env:
|
|
16
16
|
|
17
17
|
matrix:
|
18
18
|
include:
|
19
|
-
- rvm: jruby-9.
|
19
|
+
- rvm: jruby-9.1.7.0
|
20
20
|
env: AR_VERSION=4.2
|
21
21
|
before_install:
|
22
|
-
- gem
|
23
|
-
- gem install bundler -v 1.13.7 --no-rdoc --no-ri --no-document
|
22
|
+
- gem update --system
|
24
23
|
|
25
24
|
script:
|
26
25
|
- bundle exec rake test:jdbcsqlite3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## Changes in 0.17.2
|
2
|
+
|
3
|
+
### Fixes
|
4
|
+
|
5
|
+
* Fix issue where PostgreSQL cannot recognize columns if names
|
6
|
+
include mixed case characters. Thanks to @hugobgranja via \#379.
|
7
|
+
* Fix an issue for ActiveRecord 5 where serialized fields with
|
8
|
+
default values were not being typecast. Thanks to @whistlerbrk,
|
9
|
+
@jkowens via \#386.
|
10
|
+
* Add option :force_single_insert for MySQL to make sure a single
|
11
|
+
insert is attempted instead of performing multiple inserts based
|
12
|
+
on max_allowed_packet. Thanks to @mtparet via \#387.
|
13
|
+
|
1
14
|
## Changes in 0.17.1
|
2
15
|
|
3
16
|
### Fixes
|
@@ -59,12 +59,6 @@ module ActiveRecord::Import::AbstractAdapter
|
|
59
59
|
post_sql_statements
|
60
60
|
end
|
61
61
|
|
62
|
-
# Returns the maximum number of bytes that the server will allow
|
63
|
-
# in a single packet
|
64
|
-
def max_allowed_packet
|
65
|
-
NO_MAX_PACKET
|
66
|
-
end
|
67
|
-
|
68
62
|
def supports_on_duplicate_key_update?
|
69
63
|
false
|
70
64
|
end
|
@@ -7,7 +7,7 @@ module ActiveRecord::Import::MysqlAdapter
|
|
7
7
|
|
8
8
|
# +sql+ can be a single string or an array. If it is an array all
|
9
9
|
# elements that are in position >= 1 will be appended to the final SQL.
|
10
|
-
def insert_many( sql, values,
|
10
|
+
def insert_many( sql, values, options = {}, *args ) # :nodoc:
|
11
11
|
# the number of inserts default
|
12
12
|
number_of_inserts = 0
|
13
13
|
|
@@ -31,7 +31,7 @@ module ActiveRecord::Import::MysqlAdapter
|
|
31
31
|
max = max_allowed_packet
|
32
32
|
|
33
33
|
# if we can insert it all as one statement
|
34
|
-
if NO_MAX_PACKET == max || total_bytes <= max
|
34
|
+
if NO_MAX_PACKET == max || total_bytes <= max || options[:force_single_insert]
|
35
35
|
number_of_inserts += 1
|
36
36
|
sql2insert = base_sql + values.join( ',' ) + post_sql
|
37
37
|
insert( sql2insert, *args )
|
@@ -52,7 +52,7 @@ module ActiveRecord::Import::PostgreSQLAdapter
|
|
52
52
|
|
53
53
|
unless options[:no_returning] || options[:primary_key].blank?
|
54
54
|
primary_key = Array(options[:primary_key])
|
55
|
-
sql << " RETURNING #{primary_key.join(', ')}"
|
55
|
+
sql << " RETURNING \"#{primary_key.join('", "')}\""
|
56
56
|
end
|
57
57
|
|
58
58
|
sql
|
@@ -384,10 +384,12 @@ class ActiveRecord::Base
|
|
384
384
|
end
|
385
385
|
|
386
386
|
stored_attrs = respond_to?(:stored_attributes) ? stored_attributes : {}
|
387
|
+
default_values = column_defaults
|
387
388
|
|
388
389
|
array_of_attributes = models.map do |model|
|
389
390
|
column_names.map do |name|
|
390
|
-
|
391
|
+
is_stored_attr = stored_attrs.any? && stored_attrs.key?(name.to_sym)
|
392
|
+
if is_stored_attr || default_values[name].is_a?(Hash)
|
391
393
|
model.read_attribute(name.to_s)
|
392
394
|
else
|
393
395
|
model.read_attribute_before_type_cast(name.to_s)
|
@@ -681,9 +683,9 @@ class ActiveRecord::Base
|
|
681
683
|
elsif column
|
682
684
|
if defined?(type_caster_memo) && type_caster_memo.respond_to?(:type_cast_for_database) # Rails 5.0 and higher
|
683
685
|
connection_memo.quote(type_caster_memo.type_cast_for_database(column.name, val))
|
684
|
-
elsif column.respond_to?(:type_cast_from_user)
|
686
|
+
elsif column.respond_to?(:type_cast_from_user) # Rails 4.2 and higher
|
685
687
|
connection_memo.quote(column.type_cast_from_user(val), column)
|
686
|
-
else
|
688
|
+
else # Rails 3.2, 4.0 and 4.1
|
687
689
|
if serialized_attributes.include?(column.name)
|
688
690
|
val = serialized_attributes[column.name].dump(val)
|
689
691
|
end
|
data/test/import_test.rb
CHANGED
@@ -48,6 +48,14 @@ describe "#import" do
|
|
48
48
|
Widget.import Build(3, :widgets)
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
context "with uppercase letters" do
|
53
|
+
it "should import models successfully" do
|
54
|
+
assert_difference "Car.count", +3 do
|
55
|
+
Car.import Build(3, :cars)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
51
59
|
end
|
52
60
|
|
53
61
|
context "that have no primary key" do
|
data/test/models/car.rb
ADDED
@@ -154,6 +154,13 @@ ActiveRecord::Schema.define do
|
|
154
154
|
t.text :settings
|
155
155
|
end
|
156
156
|
|
157
|
+
create_table :cars, id: false, force: :cascade do |t|
|
158
|
+
t.string :Name, null: true
|
159
|
+
t.string :Features
|
160
|
+
end
|
161
|
+
|
162
|
+
add_index :cars, :Name, unique: true
|
163
|
+
|
157
164
|
execute %(
|
158
165
|
CREATE TABLE IF NOT EXISTS tags (
|
159
166
|
tag_id INT NOT NULL,
|
data/test/support/factories.rb
CHANGED
@@ -123,6 +123,18 @@ def should_support_postgresql_import_functionality
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
+
|
127
|
+
if ENV['AR_VERSION'].to_f >= 4.2
|
128
|
+
describe "with serializable fields" do
|
129
|
+
it "imports default values as correct data type" do
|
130
|
+
vendors = [Vendor.new(name: 'Vendor 1')]
|
131
|
+
assert_difference "Vendor.count", +1 do
|
132
|
+
Vendor.import vendors
|
133
|
+
end
|
134
|
+
assert_equal({}, Vendor.first.json_data)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
126
138
|
end
|
127
139
|
|
128
140
|
def should_support_postgresql_upsert_functionality
|
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.17.
|
4
|
+
version: 0.17.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- test/jdbcsqlite3/import_test.rb
|
116
116
|
- test/models/alarm.rb
|
117
117
|
- test/models/book.rb
|
118
|
+
- test/models/car.rb
|
118
119
|
- test/models/chapter.rb
|
119
120
|
- test/models/dictionary.rb
|
120
121
|
- test/models/discount.rb
|
@@ -198,6 +199,7 @@ test_files:
|
|
198
199
|
- test/jdbcsqlite3/import_test.rb
|
199
200
|
- test/models/alarm.rb
|
200
201
|
- test/models/book.rb
|
202
|
+
- test/models/car.rb
|
201
203
|
- test/models/chapter.rb
|
202
204
|
- test/models/dictionary.rb
|
203
205
|
- test/models/discount.rb
|