activerecord-import 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: 5448c6493533f39965a0b3cd0f00e3d2811e7f8feaa2f806e20b47d8db504c27
4
- data.tar.gz: fde9e0e991022d01d339da3da9b89d0523771533fc684d3d955af91b718bede2
3
+ metadata.gz: b9bf4dc4ecf93b15a493cc34134158d7df3d6391b2e6c7fafbe79b630df48ea3
4
+ data.tar.gz: ab5f7f4707598308dc9a2e7d4be5816f1d5674f63cea58e48b29f6ed87fa059a
5
5
  SHA512:
6
- metadata.gz: 1048e6bb250eb8cedb71d37dad9e13245799638e948f83016e3301ea933418327fe294438ab862d0cf1c521da51fabd8ac648f16798d1f44a62cb4784176a60a
7
- data.tar.gz: e764901dc217df8fb650a788064fcd274d7141e0a3e201ecc9011aa0ce5ce89ff7bb06d899543e084543bf52e54d8feb81c6a17d464e3a81b7df5ee187c2614d
6
+ metadata.gz: 05c4ad6281d6f0f574ee30cffed790763fb393fdf906ecc20bb8b4504f640ef9734ea1a43284f9821e543f8900aa3023bf66bcf455afcb2419e15828da618a05
7
+ data.tar.gz: cdc67be0552c3b32a980598a784964df98549a27d428b89ef3ed7385acb4c75681946e010e714770ac81ff076088c0293e26bc04bbc2e15aecd42bf86c3aecc8
@@ -37,7 +37,7 @@ addons:
37
37
  - sqlite3
38
38
  - mysql-server
39
39
  - mysql-client
40
- - postgresql-9.5-postgis-2.3
40
+ - postgresql-9.5-postgis-2.4
41
41
 
42
42
  before_install:
43
43
  - gem update --system
@@ -65,6 +65,10 @@ script:
65
65
  - bundle exec rake test:sqlite3
66
66
  - bundle exec rubocop
67
67
 
68
- dist: trusty
68
+ dist: xenial
69
+
70
+ services:
71
+ - mysql
72
+ - postgresql
69
73
 
70
74
  sudo: required
@@ -1,3 +1,15 @@
1
+ ## Changes in 1.0.3
2
+
3
+ ### New Features
4
+
5
+ * Add support for ActiveRecord 6.1.0.alpha. Thanks to @imtayadeway via
6
+ \#642.
7
+
8
+ ### Fixes
9
+
10
+ * Return an empty array for results instead of nil when importing empty
11
+ array. Thanks to @gyfis via \#636.
12
+
1
13
  ## Changes in 1.0.2
2
14
 
3
15
  ### New Features
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ version = ENV['AR_VERSION'].to_f
7
7
  mysql2_version = '0.3.0'
8
8
  mysql2_version = '0.4.0' if version >= 4.2
9
9
  sqlite3_version = '1.3.0'
10
- sqlite3_version = '1.4.0' if version >= 5.1
10
+ sqlite3_version = '1.4.0' if version >= 6.0
11
11
 
12
12
  group :development, :test do
13
13
  gem 'rubocop', '~> 0.40.0'
@@ -1,6 +1,6 @@
1
- # activerecord-import [![Build Status](https://travis-ci.org/zdennis/activerecord-import.svg?branch=master)](https://travis-ci.org/zdennis/activerecord-import)
1
+ # Activerecord-Import [![Build Status](https://travis-ci.org/zdennis/activerecord-import.svg?branch=master)](https://travis-ci.org/zdennis/activerecord-import)
2
2
 
3
- activerecord-import is a library for bulk inserting data using ActiveRecord.
3
+ Activerecord-Import is a library for bulk inserting data using ActiveRecord.
4
4
 
5
5
  One of its major features is following activerecord associations and generating the minimal
6
6
  number of SQL insert statements required, avoiding the N+1 insert problem. An example probably
@@ -23,10 +23,10 @@ an 18 hour batch process to <2 hrs.
23
23
 
24
24
  The gem provides the following high-level features:
25
25
 
26
- * activerecord-import can work with raw columns and arrays of values (fastest)
27
- * activerecord-import works with model objects (faster)
28
- * activerecord-import can perform validations (fast)
29
- * activerecord-import can perform on duplicate key updates (requires MySQL or Postgres 9.5+)
26
+ * Works with raw columns and arrays of values (fastest)
27
+ * Works with model objects (faster)
28
+ * Performs validations (fast)
29
+ * Performs on duplicate key updates (requires MySQL, SQLite 3.24.0+, or Postgres 9.5+)
30
30
 
31
31
  ## Table of Contents
32
32
 
@@ -54,6 +54,7 @@ The gem provides the following high-level features:
54
54
  * [More Information](#more-information)
55
55
  * [Contributing](#contributing)
56
56
  * [Running Tests](#running-tests)
57
+ * [Issue Triage](#issue-triage)
57
58
 
58
59
  ### Examples
59
60
 
@@ -85,7 +86,7 @@ The `import` method can take an array of column names (string or symbols) and an
85
86
 
86
87
  ```ruby
87
88
  columns = [ :title, :author ]
88
- values = [ ['Book1', 'FooManChu'], ['Book2', 'Bob Jones'] ]
89
+ values = [ ['Book1', 'George Orwell'], ['Book2', 'Bob Jones'] ]
89
90
 
90
91
  # Importing without model validations
91
92
  Book.import columns, values, validate: false
@@ -102,7 +103,7 @@ Book.import columns, values
102
103
  The `import` method can take an array of hashes. The keys map to the column names in the database.
103
104
 
104
105
  ```ruby
105
- values = [{ title: 'Book1', author: 'FooManChu' }, { title: 'Book2', author: 'Bob Jones'}]
106
+ values = [{ title: 'Book1', author: 'George Orwell' }, { title: 'Book2', author: 'Bob Jones'}]
106
107
 
107
108
  # Importing without model validations
108
109
  Book.import values, validate: false
@@ -119,7 +120,7 @@ The `import` method can take an array of column names and an array of hash objec
119
120
 
120
121
  ```ruby
121
122
  books = [
122
- { title: "Book 1", author: "FooManChu" },
123
+ { title: "Book 1", author: "George Orwell" },
123
124
  { title: "Book 2", author: "Bob Jones" }
124
125
  ]
125
126
  columns = [ :title ]
@@ -171,7 +172,7 @@ The `import` method can take an array of models. The attributes will be pulled o
171
172
 
172
173
  ```ruby
173
174
  books = [
174
- Book.new(title: "Book 1", author: "FooManChu"),
175
+ Book.new(title: "Book 1", author: "George Orwell"),
175
176
  Book.new(title: "Book 2", author: "Bob Jones")
176
177
  ]
177
178
 
@@ -189,7 +190,7 @@ The `import` method can take an array of column names and an array of models. Th
189
190
 
190
191
  ```ruby
191
192
  books = [
192
- Book.new(title: "Book 1", author: "FooManChu"),
193
+ Book.new(title: "Book 1", author: "George Orwell"),
193
194
  Book.new(title: "Book 2", author: "Bob Jones")
194
195
  ]
195
196
  columns = [ :title ]
@@ -217,7 +218,7 @@ The `import` method can take a `batch_size` option to control the number of rows
217
218
 
218
219
  ```ruby
219
220
  books = [
220
- Book.new(title: "Book 1", author: "FooManChu"),
221
+ Book.new(title: "Book 1", author: "George Orwell"),
221
222
  Book.new(title: "Book 2", author: "Bob Jones"),
222
223
  Book.new(title: "Book 1", author: "John Doe"),
223
224
  Book.new(title: "Book 2", author: "Richard Wright")
@@ -267,14 +268,14 @@ Key | Options | Default | Descripti
267
268
  For Postgres 9.5+ it adds `ON CONFLICT DO NOTHING`, for MySQL it uses `INSERT IGNORE`, and for SQLite it uses `INSERT OR IGNORE`. Cannot be enabled on a recursive import. For database adapters that normally support setting primary keys on imported objects, this option prevents that from occurring.
268
269
 
269
270
  ```ruby
270
- book = Book.create! title: "Book1", author: "FooManChu"
271
+ book = Book.create! title: "Book1", author: "George Orwell"
271
272
  book.title = "Updated Book Title"
272
273
  book.author = "Bob Barker"
273
274
 
274
275
  Book.import [book], on_duplicate_key_ignore: true
275
276
 
276
277
  book.reload.title # => "Book1" (stayed the same)
277
- book.reload.author # => "FooManChu" (stayed the same)
278
+ book.reload.author # => "George Orwell" (stayed the same)
278
279
  ```
279
280
 
280
281
  The option `:on_duplicate_key_ignore` is bypassed when `:recursive` is enabled for [PostgreSQL imports](https://github.com/zdennis/activerecord-import/wiki#recursive-example-postgresql-only).
@@ -290,7 +291,7 @@ This will use MySQL's `ON DUPLICATE KEY UPDATE` or Postgres/SQLite `ON CONFLICT
290
291
  Basic Update
291
292
 
292
293
  ```ruby
293
- book = Book.create! title: "Book1", author: "FooManChu"
294
+ book = Book.create! title: "Book1", author: "George Orwell"
294
295
  book.title = "Updated Book Title"
295
296
  book.author = "Bob Barker"
296
297
 
@@ -304,13 +305,13 @@ Book.import [book], on_duplicate_key_update: {conflict_target: [:id], columns: [
304
305
  Book.import [book], on_duplicate_key_update: [:title]
305
306
 
306
307
  book.reload.title # => "Updated Book Title" (changed)
307
- book.reload.author # => "FooManChu" (stayed the same)
308
+ book.reload.author # => "George Orwell" (stayed the same)
308
309
  ```
309
310
 
310
311
  Using the value from another column
311
312
 
312
313
  ```ruby
313
- book = Book.create! title: "Book1", author: "FooManChu"
314
+ book = Book.create! title: "Book1", author: "George Orwell"
314
315
  book.title = "Updated Book Title"
315
316
 
316
317
  # MySQL version
@@ -328,7 +329,7 @@ book.reload.author # => "Updated Book Title" (changed)
328
329
  Using Custom SQL
329
330
 
330
331
  ```ruby
331
- book = Book.create! title: "Book1", author: "FooManChu"
332
+ book = Book.create! title: "Book1", author: "George Orwell"
332
333
  book.author = "Bob Barker"
333
334
 
334
335
  # MySQL version
@@ -349,7 +350,7 @@ book.reload.author # => "Bob Barker" (changed)
349
350
  PostgreSQL Using constraints
350
351
 
351
352
  ```ruby
352
- book = Book.create! title: "Book1", author: "FooManChu", edition: 3, published_at: nil
353
+ book = Book.create! title: "Book1", author: "George Orwell", edition: 3, published_at: nil
353
354
  book.published_at = Time.now
354
355
 
355
356
  # in migration
@@ -363,7 +364,7 @@ Book.import [book], on_duplicate_key_update: {constraint_name: :for_upsert, colu
363
364
 
364
365
 
365
366
  book.reload.title # => "Book1" (stayed the same)
366
- book.reload.author # => "FooManChu" (stayed the same)
367
+ book.reload.author # => "George Orwell" (stayed the same)
367
368
  book.reload.edition # => 3 (stayed the same)
368
369
  book.reload.published_at # => 2017-10-09 (changed)
369
370
  ```
@@ -552,7 +553,7 @@ When rubygems pushes the `lib` folder onto the load path a `require` will now fi
552
553
 
553
554
  ### Conflicts With Other Gems
554
555
 
555
- `activerecord-import` adds the `.import` method onto `ActiveRecord::Base`. There are other gems, such as `elasticsearch-rails`, that do the same thing. In conflicts such as this, there is an aliased method named `.bulk_import` that can be used interchangeably.
556
+ Activerecord-Import adds the `.import` method onto `ActiveRecord::Base`. There are other gems, such as `elasticsearch-rails`, that do the same thing. In conflicts such as this, there is an aliased method named `.bulk_import` that can be used interchangeably.
556
557
 
557
558
  If you are using the `apartment` gem, there is a weird triple interaction between that gem, `activerecord-import`, and `activerecord` involving caching of the `sequence_name` of a model. This can be worked around by explcitly setting this value within the model. For example:
558
559
 
@@ -579,7 +580,7 @@ See https://github.com/zdennis/activerecord-import/issues/233 for further discus
579
580
 
580
581
  ### More Information
581
582
 
582
- For more information on activerecord-import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
583
+ For more information on Activerecord-Import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
583
584
 
584
585
  To document new information, please add to the README instead of the wiki. See https://github.com/zdennis/activerecord-import/issues/397 for discussion.
585
586
 
@@ -605,6 +606,10 @@ AR_VERSION=4.2 bundle exec rake test:postgresql test:sqlite3 test:mysql2
605
606
 
606
607
  Once you have pushed up your changes, you can find your CI results [here](https://travis-ci.org/zdennis/activerecord-import/).
607
608
 
609
+ ## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
610
+
611
+ You can triage issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to activerecord-import on CodeTriage](https://www.codetriage.com/zdennis/activerecord-import).
612
+
608
613
  # License
609
614
 
610
615
  This is licensed under the ruby license.
@@ -612,17 +617,3 @@ This is licensed under the ruby license.
612
617
  # Author
613
618
 
614
619
  Zach Dennis (zach.dennis@gmail.com)
615
-
616
- # Contributors
617
-
618
- * Jordan Owens (@jkowens)
619
- * Erik Michaels-Ober (@sferik)
620
- * Blythe Dunham
621
- * Gabe da Silveira
622
- * Henry Work
623
- * James Herdman
624
- * Marcus Crafter
625
- * Thibaud Guillaume-Gentil
626
- * Mark Van Holstyn
627
- * Victor Costan
628
- * Dillon Welch
@@ -1 +1 @@
1
- gem 'activerecord', '~> 6.0.0.rc1'
1
+ gem 'activerecord', '~> 6.0.0'
@@ -1 +1 @@
1
- gem 'activerecord', '~> 6.1.0.alpha'
1
+ gem 'activerecord', '~> 6.1.0.alpha', github: "rails/rails"
@@ -27,7 +27,13 @@ module ActiveRecord::Import
27
27
 
28
28
  # Loads the import functionality for the passed in ActiveRecord connection
29
29
  def self.load_from_connection_pool(connection_pool)
30
- require_adapter connection_pool.spec.config[:adapter]
30
+ adapter =
31
+ if connection_pool.respond_to?(:db_config) # ActiveRecord >= 6.1
32
+ connection_pool.db_config.adapter
33
+ else
34
+ connection_pool.spec.config[:adapter]
35
+ end
36
+ require_adapter adapter
31
37
  end
32
38
  end
33
39
 
@@ -630,7 +630,7 @@ class ActiveRecord::Base
630
630
  end
631
631
  # supports empty array
632
632
  elsif args.last.is_a?( Array ) && args.last.empty?
633
- return ActiveRecord::Import::Result.new([], 0, [])
633
+ return ActiveRecord::Import::Result.new([], 0, [], [])
634
634
  # supports 2-element array and array
635
635
  elsif args.size == 2 && args.first.is_a?( Array ) && args.last.is_a?( Array )
636
636
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "1.0.2".freeze
3
+ VERSION = "1.0.3".freeze
4
4
  end
5
5
  end
@@ -116,6 +116,17 @@ def should_support_postgresql_import_functionality
116
116
  assert_equal [%w(King It)], result.results
117
117
  end
118
118
 
119
+ context "when given an empty array" do
120
+ let(:result) { Book.import([], returning: %w(title)) }
121
+
122
+ setup { result }
123
+
124
+ it "returns empty arrays for ids and results" do
125
+ assert_equal [], result.ids
126
+ assert_equal [], result.results
127
+ end
128
+ end
129
+
119
130
  context "when primary key and returning overlap" do
120
131
  let(:result) { Book.import(books, returning: %w(id title)) }
121
132
 
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-01 00:00:00.000000000 Z
11
+ date: 2019-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.7.8
189
+ rubygems_version: 2.7.7
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Bulk insert extension for ActiveRecord