activerecord-import 1.0.1 → 1.0.2
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/.travis.yml +11 -12
 - data/CHANGELOG.md +15 -0
 - data/Gemfile +3 -1
 - data/README.markdown +22 -22
 - data/gemfiles/6.0.gemfile +1 -0
 - data/gemfiles/6.1.gemfile +1 -0
 - data/lib/activerecord-import/adapters/abstract_adapter.rb +1 -1
 - data/lib/activerecord-import/adapters/postgresql_adapter.rb +9 -3
 - data/lib/activerecord-import/adapters/sqlite3_adapter.rb +10 -8
 - data/lib/activerecord-import/base.rb +1 -0
 - data/lib/activerecord-import/import.rb +3 -0
 - data/lib/activerecord-import/synchronize.rb +1 -1
 - data/lib/activerecord-import/version.rb +1 -1
 - data/test/support/sqlite3/import_examples.rb +2 -15
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5448c6493533f39965a0b3cd0f00e3d2811e7f8feaa2f806e20b47d8db504c27
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fde9e0e991022d01d339da3da9b89d0523771533fc684d3d955af91b718bede2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1048e6bb250eb8cedb71d37dad9e13245799638e948f83016e3301ea933418327fe294438ab862d0cf1c521da51fabd8ac648f16798d1f44a62cb4784176a60a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e764901dc217df8fb650a788064fcd274d7141e0a3e201ecc9011aa0ce5ce89ff7bb06d899543e084543bf52e54d8feb81c6a17d464e3a81b7df5ee187c2614d
         
     | 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -1,30 +1,29 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            language: ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            cache: bundler
         
     | 
| 
       3 
3 
     | 
    
         
             
            rvm:
         
     | 
| 
       4 
     | 
    
         
            -
              - 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              - 2.5.5
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            env:
         
     | 
| 
       7 
7 
     | 
    
         
             
              global:
         
     | 
| 
       8 
8 
     | 
    
         
             
                # https://github.com/discourse/discourse/blob/master/.travis.yml
         
     | 
| 
       9 
9 
     | 
    
         
             
                - RUBY_GC_MALLOC_LIMIT=50000000
         
     | 
| 
       10 
10 
     | 
    
         
             
              matrix:
         
     | 
| 
       11 
     | 
    
         
            -
                - AR_VERSION=3.2
         
     | 
| 
       12 
     | 
    
         
            -
                - AR_VERSION=4.0
         
     | 
| 
       13 
     | 
    
         
            -
                - AR_VERSION=4.1
         
     | 
| 
       14 
     | 
    
         
            -
                - AR_VERSION=4.2
         
     | 
| 
       15 
     | 
    
         
            -
                - AR_VERSION=5.0
         
     | 
| 
       16 
11 
     | 
    
         
             
                - AR_VERSION=5.1
         
     | 
| 
       17 
12 
     | 
    
         
             
                - AR_VERSION=5.2
         
     | 
| 
      
 13 
     | 
    
         
            +
                - AR_VERSION=6.0
         
     | 
| 
       18 
14 
     | 
    
         | 
| 
       19 
15 
     | 
    
         
             
            matrix:
         
     | 
| 
       20 
16 
     | 
    
         
             
              include:
         
     | 
| 
       21 
     | 
    
         
            -
                - rvm:  
     | 
| 
      
 17 
     | 
    
         
            +
                - rvm: 2.3.8
         
     | 
| 
      
 18 
     | 
    
         
            +
                  env: AR_VERSION=3.2
         
     | 
| 
      
 19 
     | 
    
         
            +
                - rvm: 2.3.8
         
     | 
| 
      
 20 
     | 
    
         
            +
                  env: AR_VERSION=4.0
         
     | 
| 
      
 21 
     | 
    
         
            +
                - rvm: 2.3.8
         
     | 
| 
      
 22 
     | 
    
         
            +
                  env: AR_VERSION=4.1
         
     | 
| 
      
 23 
     | 
    
         
            +
                - rvm: 2.3.8
         
     | 
| 
       22 
24 
     | 
    
         
             
                  env: AR_VERSION=4.2
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                   
     | 
| 
       25 
     | 
    
         
            -
                    - bundle exec rake test:jdbcsqlite3
         
     | 
| 
       26 
     | 
    
         
            -
                    - bundle exec rake test:jdbcmysql
         
     | 
| 
       27 
     | 
    
         
            -
                    - bundle exec rake test:jdbcpostgresql
         
     | 
| 
      
 25 
     | 
    
         
            +
                - rvm: 2.3.8
         
     | 
| 
      
 26 
     | 
    
         
            +
                  env: AR_VERSION=5.0
         
     | 
| 
       28 
27 
     | 
    
         | 
| 
       29 
28 
     | 
    
         
             
              fast_finish: true
         
     | 
| 
       30 
29 
     | 
    
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,3 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ## Changes in 1.0.2
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ### New Features
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            * Add support for CockroachDB adapter. Thanks to @willie via \#605.
         
     | 
| 
      
 6 
     | 
    
         
            +
            * Add support for ActiveRecord 6.0.0.rc1. Thanks to @madeindjs, @bill-filler,
         
     | 
| 
      
 7 
     | 
    
         
            +
              @jkowens via \#619, \#623.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ### Fixes
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            * Fixes NoMethodError when attempting to use nil logger. Thanks to @MattMecel,
         
     | 
| 
      
 12 
     | 
    
         
            +
              @khiav22357.
         
     | 
| 
      
 13 
     | 
    
         
            +
            * Fix issue validating STI models. Thanks to @thejbsmith, @jkowens via
         
     | 
| 
      
 14 
     | 
    
         
            +
              \#626.
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       1 
16 
     | 
    
         
             
            ## Changes in 1.0.1
         
     | 
| 
       2 
17 
     | 
    
         | 
| 
       3 
18 
     | 
    
         
             
            ### Fixes
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -6,6 +6,8 @@ version = ENV['AR_VERSION'].to_f 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            mysql2_version = '0.3.0'
         
     | 
| 
       8 
8 
     | 
    
         
             
            mysql2_version = '0.4.0' if version >= 4.2
         
     | 
| 
      
 9 
     | 
    
         
            +
            sqlite3_version = '1.3.0'
         
     | 
| 
      
 10 
     | 
    
         
            +
            sqlite3_version = '1.4.0' if version >= 5.1
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
            group :development, :test do
         
     | 
| 
       11 
13 
     | 
    
         
             
              gem 'rubocop', '~> 0.40.0'
         
     | 
| 
         @@ -16,7 +18,7 @@ end 
     | 
|
| 
       16 
18 
     | 
    
         
             
            platforms :ruby do
         
     | 
| 
       17 
19 
     | 
    
         
             
              gem "mysql2",                 "~> #{mysql2_version}"
         
     | 
| 
       18 
20 
     | 
    
         
             
              gem "pg",                     "~> 0.9"
         
     | 
| 
       19 
     | 
    
         
            -
              gem "sqlite3",                "~>  
     | 
| 
      
 21 
     | 
    
         
            +
              gem "sqlite3",                "~> #{sqlite3_version}"
         
     | 
| 
       20 
22 
     | 
    
         
             
              gem "seamless_database_pool", "~> 1.0.20"
         
     | 
| 
       21 
23 
     | 
    
         
             
            end
         
     | 
| 
       22 
24 
     | 
    
         | 
    
        data/README.markdown
    CHANGED
    
    | 
         @@ -63,7 +63,7 @@ Without `activerecord-import`, you'd write something like this: 
     | 
|
| 
       63 
63 
     | 
    
         | 
| 
       64 
64 
     | 
    
         
             
            ```ruby
         
     | 
| 
       65 
65 
     | 
    
         
             
            10.times do |i|
         
     | 
| 
       66 
     | 
    
         
            -
              Book.create! : 
     | 
| 
      
 66 
     | 
    
         
            +
              Book.create! name: "book #{i}"
         
     | 
| 
       67 
67 
     | 
    
         
             
            end
         
     | 
| 
       68 
68 
     | 
    
         
             
            ```
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
         @@ -72,7 +72,7 @@ This would end up making 10 SQL calls. YUCK!  With `activerecord-import`, you ca 
     | 
|
| 
       72 
72 
     | 
    
         
             
            ```ruby
         
     | 
| 
       73 
73 
     | 
    
         
             
            books = []
         
     | 
| 
       74 
74 
     | 
    
         
             
            10.times do |i|
         
     | 
| 
       75 
     | 
    
         
            -
              books << Book.new(: 
     | 
| 
      
 75 
     | 
    
         
            +
              books << Book.new(name: "book #{i}")
         
     | 
| 
       76 
76 
     | 
    
         
             
            end
         
     | 
| 
       77 
77 
     | 
    
         
             
            Book.import books    # or use import!
         
     | 
| 
       78 
78 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -88,10 +88,10 @@ columns = [ :title, :author ] 
     | 
|
| 
       88 
88 
     | 
    
         
             
            values = [ ['Book1', 'FooManChu'], ['Book2', 'Bob Jones'] ]
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
90 
     | 
    
         
             
            # Importing without model validations
         
     | 
| 
       91 
     | 
    
         
            -
            Book.import columns, values, : 
     | 
| 
      
 91 
     | 
    
         
            +
            Book.import columns, values, validate: false
         
     | 
| 
       92 
92 
     | 
    
         | 
| 
       93 
93 
     | 
    
         
             
            # Import with model validations
         
     | 
| 
       94 
     | 
    
         
            -
            Book.import columns, values, : 
     | 
| 
      
 94 
     | 
    
         
            +
            Book.import columns, values, validate: true
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
96 
     | 
    
         
             
            # when not specified :validate defaults to true
         
     | 
| 
       97 
97 
     | 
    
         
             
            Book.import columns, values
         
     | 
| 
         @@ -171,15 +171,15 @@ The `import` method can take an array of models. The attributes will be pulled o 
     | 
|
| 
       171 
171 
     | 
    
         | 
| 
       172 
172 
     | 
    
         
             
            ```ruby
         
     | 
| 
       173 
173 
     | 
    
         
             
            books = [
         
     | 
| 
       174 
     | 
    
         
            -
              Book.new(: 
     | 
| 
       175 
     | 
    
         
            -
              Book.new(: 
     | 
| 
      
 174 
     | 
    
         
            +
              Book.new(title: "Book 1", author: "FooManChu"),
         
     | 
| 
      
 175 
     | 
    
         
            +
              Book.new(title: "Book 2", author: "Bob Jones")
         
     | 
| 
       176 
176 
     | 
    
         
             
            ]
         
     | 
| 
       177 
177 
     | 
    
         | 
| 
       178 
178 
     | 
    
         
             
            # without validations
         
     | 
| 
       179 
     | 
    
         
            -
            Book.import books, : 
     | 
| 
      
 179 
     | 
    
         
            +
            Book.import books, validate: false
         
     | 
| 
       180 
180 
     | 
    
         | 
| 
       181 
181 
     | 
    
         
             
            # with validations
         
     | 
| 
       182 
     | 
    
         
            -
            Book.import books, : 
     | 
| 
      
 182 
     | 
    
         
            +
            Book.import books, validate: true
         
     | 
| 
       183 
183 
     | 
    
         | 
| 
       184 
184 
     | 
    
         
             
            # when not specified :validate defaults to true
         
     | 
| 
       185 
185 
     | 
    
         
             
            Book.import books
         
     | 
| 
         @@ -189,16 +189,16 @@ The `import` method can take an array of column names and an array of models. Th 
     | 
|
| 
       189 
189 
     | 
    
         | 
| 
       190 
190 
     | 
    
         
             
            ```ruby
         
     | 
| 
       191 
191 
     | 
    
         
             
            books = [
         
     | 
| 
       192 
     | 
    
         
            -
              Book.new(: 
     | 
| 
       193 
     | 
    
         
            -
              Book.new(: 
     | 
| 
      
 192 
     | 
    
         
            +
              Book.new(title: "Book 1", author: "FooManChu"),
         
     | 
| 
      
 193 
     | 
    
         
            +
              Book.new(title: "Book 2", author: "Bob Jones")
         
     | 
| 
       194 
194 
     | 
    
         
             
            ]
         
     | 
| 
       195 
195 
     | 
    
         
             
            columns = [ :title ]
         
     | 
| 
       196 
196 
     | 
    
         | 
| 
       197 
197 
     | 
    
         
             
            # without validations
         
     | 
| 
       198 
     | 
    
         
            -
            Book.import columns, books, : 
     | 
| 
      
 198 
     | 
    
         
            +
            Book.import columns, books, validate: false
         
     | 
| 
       199 
199 
     | 
    
         | 
| 
       200 
200 
     | 
    
         
             
            # with validations
         
     | 
| 
       201 
     | 
    
         
            -
            Book.import columns, books, : 
     | 
| 
      
 201 
     | 
    
         
            +
            Book.import columns, books, validate: true
         
     | 
| 
       202 
202 
     | 
    
         | 
| 
       203 
203 
     | 
    
         
             
            # when not specified :validate defaults to true
         
     | 
| 
       204 
204 
     | 
    
         
             
            Book.import columns, books
         
     | 
| 
         @@ -217,15 +217,15 @@ The `import` method can take a `batch_size` option to control the number of rows 
     | 
|
| 
       217 
217 
     | 
    
         | 
| 
       218 
218 
     | 
    
         
             
            ```ruby
         
     | 
| 
       219 
219 
     | 
    
         
             
            books = [
         
     | 
| 
       220 
     | 
    
         
            -
              Book.new(: 
     | 
| 
       221 
     | 
    
         
            -
              Book.new(: 
     | 
| 
       222 
     | 
    
         
            -
              Book.new(: 
     | 
| 
       223 
     | 
    
         
            -
              Book.new(: 
     | 
| 
      
 220 
     | 
    
         
            +
              Book.new(title: "Book 1", author: "FooManChu"),
         
     | 
| 
      
 221 
     | 
    
         
            +
              Book.new(title: "Book 2", author: "Bob Jones"),
         
     | 
| 
      
 222 
     | 
    
         
            +
              Book.new(title: "Book 1", author: "John Doe"),
         
     | 
| 
      
 223 
     | 
    
         
            +
              Book.new(title: "Book 2", author: "Richard Wright")
         
     | 
| 
       224 
224 
     | 
    
         
             
            ]
         
     | 
| 
       225 
225 
     | 
    
         
             
            columns = [ :title ]
         
     | 
| 
       226 
226 
     | 
    
         | 
| 
       227 
227 
     | 
    
         
             
            # 2 INSERT statements for 4 records
         
     | 
| 
       228 
     | 
    
         
            -
            Book.import columns, books, : 
     | 
| 
      
 228 
     | 
    
         
            +
            Book.import columns, books, batch_size: 2
         
     | 
| 
       229 
229 
     | 
    
         
             
            ```
         
     | 
| 
       230 
230 
     | 
    
         | 
| 
       231 
231 
     | 
    
         
             
            #### Recursive
         
     | 
| 
         @@ -237,8 +237,8 @@ Assume that Books <code>has_many</code> Reviews. 
     | 
|
| 
       237 
237 
     | 
    
         
             
            ```ruby
         
     | 
| 
       238 
238 
     | 
    
         
             
            books = []
         
     | 
| 
       239 
239 
     | 
    
         
             
            10.times do |i|
         
     | 
| 
       240 
     | 
    
         
            -
              book = Book.new(: 
     | 
| 
       241 
     | 
    
         
            -
              book.reviews.build(: 
     | 
| 
      
 240 
     | 
    
         
            +
              book = Book.new(name: "book #{i}")
         
     | 
| 
      
 241 
     | 
    
         
            +
              book.reviews.build(title: "Excellent")
         
     | 
| 
       242 
242 
     | 
    
         
             
              books << book
         
     | 
| 
       243 
243 
     | 
    
         
             
            end
         
     | 
| 
       244 
244 
     | 
    
         
             
            Book.import books, recursive: true
         
     | 
| 
         @@ -248,7 +248,7 @@ Book.import books, recursive: true 
     | 
|
| 
       248 
248 
     | 
    
         | 
| 
       249 
249 
     | 
    
         
             
            Key                     | Options               | Default            | Description
         
     | 
| 
       250 
250 
     | 
    
         
             
            ----------------------- | --------------------- | ------------------ | -----------
         
     | 
| 
       251 
     | 
    
         
            -
            :validate               | `true`/`false`        | `true`             | Whether or not to run `ActiveRecord` validations (uniqueness skipped).
         
     | 
| 
      
 251 
     | 
    
         
            +
            :validate               | `true`/`false`        | `true`             | Whether or not to run `ActiveRecord` validations (uniqueness skipped). This option will always be true when using `import!`.
         
     | 
| 
       252 
252 
     | 
    
         
             
            :validate_uniqueness    | `true`/`false`        | `false`            | Whether or not to run uniqueness validations, has potential pitfalls, use with caution (requires `>= v0.27.0`).
         
     | 
| 
       253 
253 
     | 
    
         
             
            :on_duplicate_key_ignore| `true`/`false`        | `false`            | Allows skipping records with duplicate keys. See [here](https://github.com/zdennis/activerecord-import/#duplicate-key-ignore) for more details.
         
     | 
| 
       254 
254 
     | 
    
         
             
            :ignore                 | `true`/`false`        | `false`            | Alias for :on_duplicate_key_ignore.
         
     | 
| 
         @@ -383,7 +383,7 @@ articles = [ 
     | 
|
| 
       383 
383 
     | 
    
         
             
              Article.new(author_id: 3, content: '')
         
     | 
| 
       384 
384 
     | 
    
         
             
            ]
         
     | 
| 
       385 
385 
     | 
    
         | 
| 
       386 
     | 
    
         
            -
            demo = Article.import(articles 
     | 
| 
      
 386 
     | 
    
         
            +
            demo = Article.import(articles, returning: :title) # => #<struct ActiveRecord::Import::Result
         
     | 
| 
       387 
387 
     | 
    
         | 
| 
       388 
388 
     | 
    
         
             
            demo.failed_instances
         
     | 
| 
       389 
389 
     | 
    
         
             
            => [#<Article id: 3, author_id: 3, title: nil, content: "", created_at: nil, updated_at: nil>]
         
     | 
| 
         @@ -397,7 +397,7 @@ demo.ids 
     | 
|
| 
       397 
397 
     | 
    
         | 
| 
       398 
398 
     | 
    
         
             
            demo.results
         
     | 
| 
       399 
399 
     | 
    
         
             
            => ["First Article", "Second Article"] # for Postgres
         
     | 
| 
       400 
     | 
    
         
            -
            => [] for other DBs
         
     | 
| 
      
 400 
     | 
    
         
            +
            => [] # for other DBs
         
     | 
| 
       401 
401 
     | 
    
         
             
            ```
         
     | 
| 
       402 
402 
     | 
    
         | 
| 
       403 
403 
     | 
    
         
             
            ### Counter Cache
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            gem 'activerecord', '~> 6.0.0.rc1'
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            gem 'activerecord', '~> 6.1.0.alpha'
         
     | 
| 
         @@ -46,7 +46,7 @@ module ActiveRecord::Import::AbstractAdapter 
     | 
|
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  if supports_on_duplicate_key_update? && options[:on_duplicate_key_update]
         
     | 
| 
       48 
48 
     | 
    
         
             
                    post_sql_statements << sql_for_on_duplicate_key_update( table_name, options[:on_duplicate_key_update], options[:primary_key], options[:locking_column] )
         
     | 
| 
       49 
     | 
    
         
            -
                  elsif options[:on_duplicate_key_update]
         
     | 
| 
      
 49 
     | 
    
         
            +
                  elsif logger && options[:on_duplicate_key_update]
         
     | 
| 
       50 
50 
     | 
    
         
             
                    logger.warn "Ignoring on_duplicate_key_update because it is not supported by the database."
         
     | 
| 
       51 
51 
     | 
    
         
             
                  end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
         @@ -73,7 +73,7 @@ module ActiveRecord::Import::PostgreSQLAdapter 
     | 
|
| 
       73 
73 
     | 
    
         
             
                  if (options[:ignore] || options[:on_duplicate_key_ignore]) && !options[:on_duplicate_key_update] && !options[:recursive]
         
     | 
| 
       74 
74 
     | 
    
         
             
                    sql << sql_for_on_duplicate_key_ignore( table_name, options[:on_duplicate_key_ignore] )
         
     | 
| 
       75 
75 
     | 
    
         
             
                  end
         
     | 
| 
       76 
     | 
    
         
            -
                elsif options[:on_duplicate_key_ignore] && !options[:on_duplicate_key_update]
         
     | 
| 
      
 76 
     | 
    
         
            +
                elsif logger && options[:on_duplicate_key_ignore] && !options[:on_duplicate_key_update]
         
     | 
| 
       77 
77 
     | 
    
         
             
                  logger.warn "Ignoring on_duplicate_key_ignore because it is not supported by the database."
         
     | 
| 
       78 
78 
     | 
    
         
             
                end
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
         @@ -195,8 +195,8 @@ module ActiveRecord::Import::PostgreSQLAdapter 
     | 
|
| 
       195 
195 
     | 
    
         
             
                exception.is_a?(ActiveRecord::StatementInvalid) && exception.to_s.include?('duplicate key')
         
     | 
| 
       196 
196 
     | 
    
         
             
              end
         
     | 
| 
       197 
197 
     | 
    
         | 
| 
       198 
     | 
    
         
            -
              def supports_on_duplicate_key_update? 
     | 
| 
       199 
     | 
    
         
            -
                 
     | 
| 
      
 198 
     | 
    
         
            +
              def supports_on_duplicate_key_update?
         
     | 
| 
      
 199 
     | 
    
         
            +
                database_version >= MIN_VERSION_FOR_UPSERT
         
     | 
| 
       200 
200 
     | 
    
         
             
              end
         
     | 
| 
       201 
201 
     | 
    
         | 
| 
       202 
202 
     | 
    
         
             
              def supports_setting_primary_key_of_imported_objects?
         
     | 
| 
         @@ -208,4 +208,10 @@ module ActiveRecord::Import::PostgreSQLAdapter 
     | 
|
| 
       208 
208 
     | 
    
         
             
                  results << "\"#{locking_column}\"=EXCLUDED.\"#{locking_column}\"+1"
         
     | 
| 
       209 
209 
     | 
    
         
             
                end
         
     | 
| 
       210 
210 
     | 
    
         
             
              end
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
              private
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
              def database_version
         
     | 
| 
      
 215 
     | 
    
         
            +
                defined?(postgresql_version) ? postgresql_version : super
         
     | 
| 
      
 216 
     | 
    
         
            +
              end
         
     | 
| 
       211 
217 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,16 +9,12 @@ module ActiveRecord::Import::SQLite3Adapter 
     | 
|
| 
       9 
9 
     | 
    
         
             
              # Override our conformance to ActiveRecord::Import::ImportSupport interface
         
     | 
| 
       10 
10 
     | 
    
         
             
              # to ensure that we only support import in supported version of SQLite.
         
     | 
| 
       11 
11 
     | 
    
         
             
              # Which INSERT statements with multiple value sets was introduced in 3.7.11.
         
     | 
| 
       12 
     | 
    
         
            -
              def supports_import? 
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                  true
         
     | 
| 
       15 
     | 
    
         
            -
                else
         
     | 
| 
       16 
     | 
    
         
            -
                  false
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              def supports_import?
         
     | 
| 
      
 13 
     | 
    
         
            +
                database_version >= MIN_VERSION_FOR_IMPORT
         
     | 
| 
       18 
14 
     | 
    
         
             
              end
         
     | 
| 
       19 
15 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
              def supports_on_duplicate_key_update? 
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
      
 16 
     | 
    
         
            +
              def supports_on_duplicate_key_update?
         
     | 
| 
      
 17 
     | 
    
         
            +
                database_version >= MIN_VERSION_FOR_UPSERT
         
     | 
| 
       22 
18 
     | 
    
         
             
              end
         
     | 
| 
       23 
19 
     | 
    
         | 
| 
       24 
20 
     | 
    
         
             
              # +sql+ can be a single string or an array. If it is an array all
         
     | 
| 
         @@ -175,4 +171,10 @@ module ActiveRecord::Import::SQLite3Adapter 
     | 
|
| 
       175 
171 
     | 
    
         
             
                  results << "\"#{locking_column}\"=EXCLUDED.\"#{locking_column}\"+1"
         
     | 
| 
       176 
172 
     | 
    
         
             
                end
         
     | 
| 
       177 
173 
     | 
    
         
             
              end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
              private
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
              def database_version
         
     | 
| 
      
 178 
     | 
    
         
            +
                defined?(sqlite_version) ? sqlite_version : super
         
     | 
| 
      
 179 
     | 
    
         
            +
              end
         
     | 
| 
       178 
180 
     | 
    
         
             
            end
         
     | 
| 
         @@ -26,6 +26,7 @@ module ActiveRecord::Import #:nodoc: 
     | 
|
| 
       26 
26 
     | 
    
         
             
              class Validator
         
     | 
| 
       27 
27 
     | 
    
         
             
                def initialize(klass, options = {})
         
     | 
| 
       28 
28 
     | 
    
         
             
                  @options = options
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @validator_class = klass
         
     | 
| 
       29 
30 
     | 
    
         
             
                  init_validations(klass)
         
     | 
| 
       30 
31 
     | 
    
         
             
                end
         
     | 
| 
       31 
32 
     | 
    
         | 
| 
         @@ -70,6 +71,8 @@ module ActiveRecord::Import #:nodoc: 
     | 
|
| 
       70 
71 
     | 
    
         
             
                end
         
     | 
| 
       71 
72 
     | 
    
         | 
| 
       72 
73 
     | 
    
         
             
                def valid_model?(model)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  init_validations(model.class) unless model.class == @validator_class
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
       73 
76 
     | 
    
         
             
                  validation_context = @options[:validate_with_context]
         
     | 
| 
       74 
77 
     | 
    
         
             
                  validation_context ||= (model.new_record? ? :create : :update)
         
     | 
| 
       75 
78 
     | 
    
         
             
                  current_context = model.send(:validation_context)
         
     | 
| 
         @@ -39,8 +39,8 @@ module ActiveRecord # :nodoc: 
     | 
|
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                    next unless matched_instance
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
                    instance.send :clear_aggregation_cache
         
     | 
| 
       43 
42 
     | 
    
         
             
                    instance.send :clear_association_cache
         
     | 
| 
      
 43 
     | 
    
         
            +
                    instance.send :clear_aggregation_cache if instance.respond_to?(:clear_aggregation_cache, true)
         
     | 
| 
       44 
44 
     | 
    
         
             
                    instance.instance_variable_set :@attributes, matched_instance.instance_variable_get(:@attributes)
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                    if instance.respond_to?(:clear_changes_information)
         
     | 
| 
         @@ -5,21 +5,8 @@ def should_support_sqlite3_import_functionality 
     | 
|
| 
       5 
5 
     | 
    
         
             
              end
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              describe "#supports_imports?" do
         
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
       10 
     | 
    
         
            -
                    version = ActiveRecord::ConnectionAdapters::SQLite3Adapter::Version.new("3.7.11")
         
     | 
| 
       11 
     | 
    
         
            -
                    assert ActiveRecord::Base.supports_import?(version)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                    version = ActiveRecord::ConnectionAdapters::SQLite3Adapter::Version.new("3.7.12")
         
     | 
| 
       14 
     | 
    
         
            -
                    assert ActiveRecord::Base.supports_import?(version)
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                context "and SQLite less than 3.7.11" do
         
     | 
| 
       19 
     | 
    
         
            -
                  it "doesn't support import" do
         
     | 
| 
       20 
     | 
    
         
            -
                    version = ActiveRecord::ConnectionAdapters::SQLite3Adapter::Version.new("3.7.10")
         
     | 
| 
       21 
     | 
    
         
            -
                    assert !ActiveRecord::Base.supports_import?(version)
         
     | 
| 
       22 
     | 
    
         
            -
                  end
         
     | 
| 
      
 8 
     | 
    
         
            +
                it "should support import" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                  assert ActiveRecord::Base.supports_import?
         
     | 
| 
       23 
10 
     | 
    
         
             
                end
         
     | 
| 
       24 
11 
     | 
    
         
             
              end
         
     | 
| 
       25 
12 
     | 
    
         | 
    
        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.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: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-06-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activerecord
         
     | 
| 
         @@ -75,6 +75,8 @@ files: 
     | 
|
| 
       75 
75 
     | 
    
         
             
            - gemfiles/5.0.gemfile
         
     | 
| 
       76 
76 
     | 
    
         
             
            - gemfiles/5.1.gemfile
         
     | 
| 
       77 
77 
     | 
    
         
             
            - gemfiles/5.2.gemfile
         
     | 
| 
      
 78 
     | 
    
         
            +
            - gemfiles/6.0.gemfile
         
     | 
| 
      
 79 
     | 
    
         
            +
            - gemfiles/6.1.gemfile
         
     | 
| 
       78 
80 
     | 
    
         
             
            - lib/activerecord-import.rb
         
     | 
| 
       79 
81 
     | 
    
         
             
            - lib/activerecord-import/active_record/adapters/abstract_adapter.rb
         
     | 
| 
       80 
82 
     | 
    
         
             
            - lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb
         
     | 
| 
         @@ -184,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       184 
186 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       185 
187 
     | 
    
         
             
            requirements: []
         
     | 
| 
       186 
188 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       187 
     | 
    
         
            -
            rubygems_version: 2.7. 
     | 
| 
      
 189 
     | 
    
         
            +
            rubygems_version: 2.7.8
         
     | 
| 
       188 
190 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       189 
191 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       190 
192 
     | 
    
         
             
            summary: Bulk insert extension for ActiveRecord
         
     |