Skip to content

Commit

Permalink
Merge pull request #161 from jkowens/master
Browse files Browse the repository at this point in the history
Upgrade to activerecord-import 0.27.0
  • Loading branch information
workgena committed Jan 15, 2019
2 parents 838e257 + 66dba6e commit 99c17fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ Tool | Description
--------------------- | -----------
:back |resource action to redirect after processing
:csv_options |hash with column separator, row separator, etc
:validate |bool means perform validations or not
:validate |bool (true by default), perform validations or not
:batch_transaction |bool (false by default), if transaction is used when batch importing and works when :validate is set to true
:batch_size |integer value of max record count inserted by 1 query/transaction
:batch_transaction |bool (false by default), if transaction is used when batch importing and works when :validate is set to true
:before_import |proc for before import action, hook called with importer object
:after_import |proc for after import action, hook called with importer object
:before_batch_import |proc for before each batch action, called with importer object
:after_batch_import |proc for after each batch action, called with importer object
: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.
: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
: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
:ignore |bool, alias for on_duplicate_key_ignore
:timestamps |bool, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
:ignore |bool, tells activerecord-import to use MySQL's INSERT IGNORE ability
:template |custom template rendering
:template_object |object passing to view
:resource_class |resource class name
Expand Down
2 changes: 1 addition & 1 deletion active_admin_import.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.name = 'active_admin_import'
gem.require_paths = ['lib']
gem.version = ActiveAdminImport::VERSION
gem.add_runtime_dependency 'activerecord-import', '~> 0.17.0'
gem.add_runtime_dependency 'activerecord-import', '>= 0.27.0'
gem.add_runtime_dependency 'rchardet', '~> 1.6'
gem.add_runtime_dependency 'rubyzip', '~> 1.2'
gem.add_dependency 'activeadmin', '>= 1.0.0.pre2'
Expand Down
17 changes: 15 additions & 2 deletions lib/active_admin_import/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Importer
OPTIONS = [
:validate,
:on_duplicate_key_update,
:on_duplicate_key_ignore,
:ignore,
:timestamps,
:before_import,
Expand Down Expand Up @@ -48,7 +49,16 @@ def import
end

def import_options
@import_options ||= options.slice(:validate, :on_duplicate_key_update, :ignore, :timestamps, :batch_transaction)
@import_options ||= options.slice(
:validate,
:validate_uniqueness,
:on_duplicate_key_update,
:on_duplicate_key_ignore,
:ignore,
:timestamps,
:batch_transaction,
:batch_size
)
end

def batch_replace(header_key, options)
Expand Down Expand Up @@ -134,7 +144,10 @@ def batch_import
end

def assign_options(options)
@options = { batch_size: 1000, validate: true }.merge(options.slice(*OPTIONS))
@options = {
batch_size: 1000,
validate_uniqueness: true
}.merge(options.slice(*OPTIONS))
detect_csv_options
end

Expand Down

0 comments on commit 99c17fd

Please sign in to comment.