Skip to content

Commit 66dba6e

Browse files
committed
Upgrade to activerecord-import 0.27.0
1 parent 838e257 commit 66dba6e

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ Tool | Description
5555
--------------------- | -----------
5656
:back |resource action to redirect after processing
5757
:csv_options |hash with column separator, row separator, etc
58-
:validate |bool means perform validations or not
58+
:validate |bool (true by default), perform validations or not
59+
:batch_transaction |bool (false by default), if transaction is used when batch importing and works when :validate is set to true
5960
:batch_size |integer value of max record count inserted by 1 query/transaction
60-
:batch_transaction |bool (false by default), if transaction is used when batch importing and works when :validate is set to true
6161
:before_import |proc for before import action, hook called with importer object
6262
:after_import |proc for after import action, hook called with importer object
6363
:before_batch_import |proc for before each batch action, called with importer object
6464
:after_batch_import |proc for after each batch action, called with importer object
65-
:on_duplicate_key_update|an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE or Postgres 9.5+ ON CONFLICT DO UPDATE ability.
65+
:on_duplicate_key_update|an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE or Postgres 9.5+/SQLite 3.24.0+ ON CONFLICT DO UPDATE ability
66+
:on_duplicate_key_ignore|bool, tells activerecord-import to use MySQL's INSERT IGNORE or Postgres 9.5+ ON CONFLICT DO NOTHING or SQLite's INSERT OR IGNORE ability
67+
:ignore |bool, alias for on_duplicate_key_ignore
6668
:timestamps |bool, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
67-
:ignore |bool, tells activerecord-import to use MySQL's INSERT IGNORE ability
6869
:template |custom template rendering
6970
:template_object |object passing to view
7071
:resource_class |resource class name

active_admin_import.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
1515
gem.name = 'active_admin_import'
1616
gem.require_paths = ['lib']
1717
gem.version = ActiveAdminImport::VERSION
18-
gem.add_runtime_dependency 'activerecord-import', '~> 0.17.0'
18+
gem.add_runtime_dependency 'activerecord-import', '>= 0.27.0'
1919
gem.add_runtime_dependency 'rchardet', '~> 1.6'
2020
gem.add_runtime_dependency 'rubyzip', '~> 1.2'
2121
gem.add_dependency 'activeadmin', '>= 1.0.0.pre2'

lib/active_admin_import/importer.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Importer
88
OPTIONS = [
99
:validate,
1010
:on_duplicate_key_update,
11+
:on_duplicate_key_ignore,
1112
:ignore,
1213
:timestamps,
1314
:before_import,
@@ -48,7 +49,16 @@ def import
4849
end
4950

5051
def import_options
51-
@import_options ||= options.slice(:validate, :on_duplicate_key_update, :ignore, :timestamps, :batch_transaction)
52+
@import_options ||= options.slice(
53+
:validate,
54+
:validate_uniqueness,
55+
:on_duplicate_key_update,
56+
:on_duplicate_key_ignore,
57+
:ignore,
58+
:timestamps,
59+
:batch_transaction,
60+
:batch_size
61+
)
5262
end
5363

5464
def batch_replace(header_key, options)
@@ -134,7 +144,10 @@ def batch_import
134144
end
135145

136146
def assign_options(options)
137-
@options = { batch_size: 1000, validate: true }.merge(options.slice(*OPTIONS))
147+
@options = {
148+
batch_size: 1000,
149+
validate_uniqueness: true
150+
}.merge(options.slice(*OPTIONS))
138151
detect_csv_options
139152
end
140153

0 commit comments

Comments
 (0)