activerecord-import 1.1.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +107 -0
- data/.rubocop.yml +74 -8
- data/Brewfile +3 -1
- data/CHANGELOG.md +38 -3
- data/Gemfile +5 -7
- data/README.markdown +13 -12
- data/Rakefile +2 -0
- data/activerecord-import.gemspec +4 -3
- data/benchmarks/benchmark.rb +7 -1
- data/benchmarks/lib/base.rb +2 -0
- data/benchmarks/lib/cli_parser.rb +3 -1
- data/benchmarks/lib/float.rb +2 -0
- data/benchmarks/lib/mysql2_benchmark.rb +2 -0
- data/benchmarks/lib/output_to_csv.rb +2 -0
- data/benchmarks/lib/output_to_html.rb +4 -2
- data/benchmarks/models/test_innodb.rb +2 -0
- data/benchmarks/models/test_memory.rb +2 -0
- data/benchmarks/models/test_myisam.rb +2 -0
- data/benchmarks/schema/mysql2_schema.rb +2 -0
- data/gemfiles/4.2.gemfile +2 -0
- data/gemfiles/5.0.gemfile +2 -0
- data/gemfiles/5.1.gemfile +2 -0
- data/gemfiles/5.2.gemfile +2 -0
- data/gemfiles/6.0.gemfile +2 -0
- data/gemfiles/6.1.gemfile +3 -0
- data/gemfiles/7.0.gemfile +4 -0
- data/lib/activerecord-import/active_record/adapters/abstract_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb +6 -4
- data/lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/postgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/em_mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql_adapter.rb +3 -1
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +41 -30
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +8 -8
- data/lib/activerecord-import/base.rb +3 -1
- data/lib/activerecord-import/import.rb +62 -32
- data/lib/activerecord-import/mysql2.rb +2 -0
- data/lib/activerecord-import/postgresql.rb +2 -0
- data/lib/activerecord-import/sqlite3.rb +2 -0
- data/lib/activerecord-import/synchronize.rb +3 -1
- data/lib/activerecord-import/value_sets_parser.rb +2 -0
- data/lib/activerecord-import/version.rb +3 -1
- data/lib/activerecord-import.rb +3 -1
- data/test/adapters/jdbcmysql.rb +2 -0
- data/test/adapters/jdbcpostgresql.rb +2 -0
- data/test/adapters/jdbcsqlite3.rb +2 -0
- data/test/adapters/makara_postgis.rb +2 -0
- data/test/adapters/mysql2.rb +2 -0
- data/test/adapters/mysql2_makara.rb +2 -0
- data/test/adapters/mysql2spatial.rb +2 -0
- data/test/adapters/postgis.rb +2 -0
- data/test/adapters/postgresql.rb +2 -0
- data/test/adapters/postgresql_makara.rb +2 -0
- data/test/adapters/seamless_database_pool.rb +2 -0
- data/test/adapters/spatialite.rb +2 -0
- data/test/adapters/sqlite3.rb +2 -0
- data/test/{travis → github}/database.yml +3 -1
- data/test/import_test.rb +45 -2
- data/test/jdbcmysql/import_test.rb +2 -0
- data/test/jdbcpostgresql/import_test.rb +2 -0
- data/test/jdbcsqlite3/import_test.rb +2 -0
- data/test/makara_postgis/import_test.rb +2 -0
- data/test/models/account.rb +2 -0
- data/test/models/alarm.rb +2 -0
- data/test/models/animal.rb +2 -0
- data/test/models/bike_maker.rb +2 -0
- data/test/models/book.rb +2 -0
- data/test/models/car.rb +2 -0
- data/test/models/card.rb +5 -0
- data/test/models/chapter.rb +2 -0
- data/test/models/customer.rb +8 -0
- data/test/models/deck.rb +8 -0
- data/test/models/dictionary.rb +2 -0
- data/test/models/discount.rb +2 -0
- data/test/models/end_note.rb +2 -0
- data/test/models/group.rb +2 -0
- data/test/models/order.rb +8 -0
- data/test/models/playing_card.rb +4 -0
- data/test/models/promotion.rb +2 -0
- data/test/models/question.rb +2 -0
- data/test/models/rule.rb +2 -0
- data/test/models/tag.rb +3 -0
- data/test/models/tag_alias.rb +5 -0
- data/test/models/topic.rb +2 -0
- data/test/models/user.rb +2 -0
- data/test/models/user_token.rb +2 -0
- data/test/models/vendor.rb +2 -0
- data/test/models/widget.rb +2 -0
- data/test/mysql2/import_test.rb +2 -0
- data/test/mysql2_makara/import_test.rb +2 -0
- data/test/mysqlspatial2/import_test.rb +2 -0
- data/test/postgis/import_test.rb +2 -0
- data/test/postgresql/import_test.rb +2 -0
- data/test/schema/generic_schema.rb +33 -0
- data/test/schema/jdbcpostgresql_schema.rb +2 -0
- data/test/schema/mysql2_schema.rb +2 -0
- data/test/schema/postgis_schema.rb +2 -0
- data/test/schema/postgresql_schema.rb +2 -0
- data/test/schema/sqlite3_schema.rb +2 -0
- data/test/schema/version.rb +2 -0
- data/test/sqlite3/import_test.rb +2 -0
- data/test/support/active_support/test_case_extensions.rb +2 -0
- data/test/support/assertions.rb +2 -0
- data/test/support/factories.rb +2 -0
- data/test/support/generate.rb +4 -2
- data/test/support/mysql/import_examples.rb +2 -1
- data/test/support/postgresql/import_examples.rb +65 -2
- data/test/support/shared_examples/on_duplicate_key_ignore.rb +2 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +2 -0
- data/test/support/shared_examples/recursive_import.rb +23 -1
- data/test/support/sqlite3/import_examples.rb +2 -1
- data/test/synchronize_test.rb +2 -0
- data/test/test_helper.rb +19 -2
- data/test/value_sets_bytes_parser_test.rb +2 -0
- data/test/value_sets_records_parser_test.rb +2 -0
- metadata +25 -15
- data/.travis.yml +0 -76
- data/gemfiles/3.2.gemfile +0 -2
- data/gemfiles/4.0.gemfile +0 -2
- data/gemfiles/4.1.gemfile +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b9c717d31cf5a4012568c9d8497947466408be7fef5610fba9143f7a911ed7c
|
4
|
+
data.tar.gz: 925bc5f645152eeb09f9583e9d50b9be67c4bfa8049c303571f82649262e4d5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409d66e4d4e6e9ac31940cea097837d76c93cbeb4b95461323afc6a5f2ace736f945705e5ef33f2a851bb92c13c27e19ffbc14c7e776a0366f1d76091cafd51f
|
7
|
+
data.tar.gz: 6a0eaa48b85f7b1863dfb2b04c3c193a5e7e1108084556ba1b25fa303bccb40f62dd706ec8d4b5c3394239f167eb1807dfff4fe292edc1e4ad550719a9a63446
|
@@ -0,0 +1,107 @@
|
|
1
|
+
name: Test
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
services:
|
6
|
+
postgres:
|
7
|
+
image: postgis/postgis:10-2.5
|
8
|
+
env:
|
9
|
+
POSTGRES_USER: postgres
|
10
|
+
POSTGRES_PASSWORD: postgres
|
11
|
+
ports:
|
12
|
+
- 5432:5432
|
13
|
+
# Set health checks to wait until postgres has started
|
14
|
+
options: >-
|
15
|
+
--health-cmd pg_isready
|
16
|
+
--health-interval 10s
|
17
|
+
--health-timeout 5s
|
18
|
+
--health-retries 5
|
19
|
+
strategy:
|
20
|
+
fail-fast: false
|
21
|
+
matrix:
|
22
|
+
ruby:
|
23
|
+
- 3.1
|
24
|
+
env:
|
25
|
+
- AR_VERSION: '7.0'
|
26
|
+
RUBYOPT: --enable-frozen-string-literal
|
27
|
+
- AR_VERSION: 6.1
|
28
|
+
RUBYOPT: --enable-frozen-string-literal
|
29
|
+
include:
|
30
|
+
- ruby: '3.0'
|
31
|
+
env:
|
32
|
+
AR_VERSION: '7.0'
|
33
|
+
- ruby: '3.0'
|
34
|
+
env:
|
35
|
+
AR_VERSION: 6.1
|
36
|
+
- ruby: 2.7
|
37
|
+
env:
|
38
|
+
AR_VERSION: '7.0'
|
39
|
+
- ruby: 2.7
|
40
|
+
env:
|
41
|
+
AR_VERSION: 6.1
|
42
|
+
- ruby: 2.7
|
43
|
+
env:
|
44
|
+
AR_VERSION: '6.0'
|
45
|
+
- ruby: 2.6
|
46
|
+
env:
|
47
|
+
AR_VERSION: 5.2
|
48
|
+
- ruby: 2.6
|
49
|
+
env:
|
50
|
+
AR_VERSION: 5.1
|
51
|
+
- ruby: 2.4
|
52
|
+
env:
|
53
|
+
AR_VERSION: '5.0'
|
54
|
+
- ruby: 2.4
|
55
|
+
env:
|
56
|
+
AR_VERSION: 4.2
|
57
|
+
runs-on: ubuntu-latest
|
58
|
+
env:
|
59
|
+
AR_VERSION: ${{ matrix.env.AR_VERSION }}
|
60
|
+
DB_DATABASE: activerecord_import_test
|
61
|
+
steps:
|
62
|
+
- uses: actions/checkout@v2
|
63
|
+
- uses: ruby/setup-ruby@v1
|
64
|
+
with:
|
65
|
+
ruby-version: ${{ matrix.ruby }}
|
66
|
+
bundler-cache: true
|
67
|
+
- name: Set up databases
|
68
|
+
run: |
|
69
|
+
sudo /etc/init.d/mysql start
|
70
|
+
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }} CHARACTER SET utf8 COLLATE utf8_general_ci;' -u root -proot
|
71
|
+
psql -h localhost -U postgres -c 'create database ${{ env.DB_DATABASE }};'
|
72
|
+
psql -h localhost -U postgres -d ${{ env.DB_DATABASE }} -c 'create extension if not exists hstore;'
|
73
|
+
psql -h localhost -U postgres -c 'create extension if not exists postgis;'
|
74
|
+
psql -h localhost -U postgres -c 'create extension if not exists "uuid-ossp";'
|
75
|
+
cp test/github/database.yml test/database.yml
|
76
|
+
env:
|
77
|
+
PGPASSWORD: postgres
|
78
|
+
- name: Run tests with mysql2
|
79
|
+
run: |
|
80
|
+
bundle exec rake test:mysql2
|
81
|
+
bundle exec rake test:mysql2_makara
|
82
|
+
bundle exec rake test:mysql2spatial
|
83
|
+
- name: Run tests with postgresql
|
84
|
+
run: |
|
85
|
+
bundle exec rake test:postgis
|
86
|
+
bundle exec rake test:postgresql
|
87
|
+
bundle exec rake test:postgresql_makara
|
88
|
+
- name: Run tests with seamless_database_pool
|
89
|
+
run: |
|
90
|
+
bundle exec rake test:seamless_database_pool
|
91
|
+
if: ${{ matrix.ruby < '3.0' }}
|
92
|
+
- name: Run tests with sqlite
|
93
|
+
run: |
|
94
|
+
bundle exec rake test:spatialite
|
95
|
+
bundle exec rake test:sqlite3
|
96
|
+
lint:
|
97
|
+
runs-on: ubuntu-latest
|
98
|
+
env:
|
99
|
+
AR_VERSION: '7.0'
|
100
|
+
steps:
|
101
|
+
- uses: actions/checkout@v2
|
102
|
+
- uses: ruby/setup-ruby@v1
|
103
|
+
with:
|
104
|
+
ruby-version: 2.7
|
105
|
+
bundler-cache: true
|
106
|
+
- name: Run Rubocop
|
107
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
|
-
Lint/EndAlignment:
|
4
|
-
AlignWith: variable
|
5
|
-
|
6
3
|
Metrics/AbcSize:
|
7
4
|
Enabled: false
|
8
5
|
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
9
|
Metrics/ClassLength:
|
10
10
|
Enabled: false
|
11
11
|
|
@@ -24,8 +24,8 @@ Metrics/ModuleLength:
|
|
24
24
|
Metrics/PerceivedComplexity:
|
25
25
|
Enabled: false
|
26
26
|
|
27
|
-
Style/
|
28
|
-
|
27
|
+
Style/CommentedKeyword:
|
28
|
+
Enabled: false
|
29
29
|
|
30
30
|
Style/ClassAndModuleChildren:
|
31
31
|
Enabled: false
|
@@ -33,10 +33,25 @@ Style/ClassAndModuleChildren:
|
|
33
33
|
Style/Documentation:
|
34
34
|
Enabled: false
|
35
35
|
|
36
|
-
Style/
|
36
|
+
Style/EvalWithLocation:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/ExpandPathArguments:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/GuardClause:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/IfUnlessModifier:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/NumericPredicate:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/PercentLiteralDelimiters:
|
37
52
|
Enabled: false
|
38
53
|
|
39
|
-
Style/
|
54
|
+
Style/RedundantBegin:
|
40
55
|
Enabled: false
|
41
56
|
|
42
57
|
Style/SpecialGlobalVars:
|
@@ -45,5 +60,56 @@ Style/SpecialGlobalVars:
|
|
45
60
|
Style/StringLiterals:
|
46
61
|
Enabled: false
|
47
62
|
|
48
|
-
Style/
|
63
|
+
Style/SymbolArray:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/TrailingCommaInArrayLiteral:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Layout/AlignArguments:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Layout/AlignParameters:
|
73
|
+
EnforcedStyle: with_fixed_indentation
|
74
|
+
|
75
|
+
Layout/EndAlignment:
|
76
|
+
EnforcedStyleAlignWith: variable
|
77
|
+
|
78
|
+
Layout/ElseAlignment:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Layout/EmptyLineAfterGuardClause:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
Layout/IndentHeredoc:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
Layout/SpaceInsideParens:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Layout/SpaceInsidePercentLiteralDelimiters:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Lint/ErbNewArguments:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
Lint/MissingCopEnableDirective:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
Lint/PercentStringArray:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Naming/HeredocDelimiterNaming:
|
103
|
+
Enabled: false
|
104
|
+
|
105
|
+
Naming/UncommunicativeMethodParamName:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
Security/YAMLLoad:
|
109
|
+
Enabled: false
|
110
|
+
|
111
|
+
Gemspec/RequiredRubyVersion:
|
112
|
+
Enabled: false
|
113
|
+
|
114
|
+
Bundler/OrderedGems:
|
49
115
|
Enabled: false
|
data/Brewfile
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
## Changes in 1.4.1
|
2
|
+
|
3
|
+
### Fixes
|
4
|
+
|
5
|
+
* Fix importing models that have required belongs_to associations and use composite primary keys. Thanks to @thoughtbot-summer vi \##783.
|
6
|
+
|
7
|
+
## Changes in 1.4.0
|
8
|
+
|
9
|
+
### New Features
|
10
|
+
|
11
|
+
* Enable compatibility with frozen string literals. Thanks to @desheikh via \##760.
|
12
|
+
|
13
|
+
## Changes in 1.3.0
|
14
|
+
|
15
|
+
### Fixes
|
16
|
+
|
17
|
+
* Ensure correct timestamp values are returned for models after insert. Thanks to @kos1kov via \##756.
|
18
|
+
* Restore database_version method to public scope. Thanks to @beauraF via \##753.
|
19
|
+
|
20
|
+
### New Features
|
21
|
+
|
22
|
+
* Add support for ActiveRecord 7.0. Thanks to @nickhammond, @ryanwood, @jkowens via \##749 and \##752.
|
23
|
+
* Add support for compound foreign keys. Thanks to @Uladzimiro via \##750.
|
24
|
+
* Add support for :recursive combined with on_duplicate_key_update: :all. Thanks to @deathwish via \##746.
|
25
|
+
|
26
|
+
## Changes in 1.2.0
|
27
|
+
|
28
|
+
### Fixes
|
29
|
+
|
30
|
+
* Update JDBC MySQL adapter to use mysql2 connection adapter. Thanks to @terencechow via \##744.
|
31
|
+
* Fix importing STI models with ActiveRecord 6. Thanks to @clemens1483 via \##743.
|
32
|
+
* Use polymorphic_name instead of base_class.name for imports. Thanks to @kmhajjar via \##741.
|
33
|
+
* Fix compatibility issue with composite primary keys. Thanks to @dlanileonardo via \##737.
|
34
|
+
* Prevent double validation of associations on recursive import.
|
35
|
+
|
1
36
|
## Changes in 1.1.0
|
2
37
|
|
3
38
|
### New Features
|
@@ -27,7 +62,7 @@
|
|
27
62
|
|
28
63
|
* Handle after_initialize callbacks. Thanks to @AhMohsen46 via \#691 and
|
29
64
|
\#692.
|
30
|
-
* Fix regression introduced in 1.0.4.
|
65
|
+
* Fix regression introduced in 1.0.4. Explicitly allow adapters to
|
31
66
|
support on duplicate key update. Thanks to @dsobiera, @jkowens via \#696.
|
32
67
|
|
33
68
|
## Changes in 1.0.5
|
@@ -36,7 +71,7 @@
|
|
36
71
|
|
37
72
|
* Allow serialized attributes to be returned from import. Thanks to @timanovsky, @jkowens via \#660.
|
38
73
|
* Return ActiveRecord::Connection from
|
39
|
-
|
74
|
+
ActiveRecord::Base#establish_connection. Thanks to @reverentF via
|
40
75
|
\#663.
|
41
76
|
* Support PostgreSQL array. Thanks to @ujihisa via \#669.
|
42
77
|
* Skip loading association ids when column changed. Thanks to @Aristat
|
@@ -91,7 +126,7 @@
|
|
91
126
|
* Fix import issue for models with Postgresql json/jsonb fields. Thanks
|
92
127
|
to @stokarenko via \#594.
|
93
128
|
* Fix issue importing models with timestamps that contain timezone
|
94
|
-
information.
|
129
|
+
information. Thanks to @dekaikiwi, @jkowens via \#598.
|
95
130
|
* Ignore :no_returning when using :recursive option. Thanks to @dgollahon, @jkowens
|
96
131
|
via \#599.
|
97
132
|
|
data/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
@@ -13,7 +15,7 @@ pg_version = '0.9'
|
|
13
15
|
pg_version = '1.1' if version >= 6.1
|
14
16
|
|
15
17
|
group :development, :test do
|
16
|
-
gem 'rubocop', '~> 0.
|
18
|
+
gem 'rubocop', '~> 0.71.0'
|
17
19
|
gem 'rake'
|
18
20
|
end
|
19
21
|
|
@@ -22,7 +24,8 @@ platforms :ruby do
|
|
22
24
|
gem "mysql2", "~> #{mysql2_version}"
|
23
25
|
gem "pg", "~> #{pg_version}"
|
24
26
|
gem "sqlite3", "~> #{sqlite3_version}"
|
25
|
-
|
27
|
+
# seamless_database_pool requires Ruby ~> 2.0
|
28
|
+
gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
|
26
29
|
end
|
27
30
|
|
28
31
|
platforms :jruby do
|
@@ -44,14 +47,9 @@ platforms :jruby do
|
|
44
47
|
gem "ruby-debug", "= 0.10.4"
|
45
48
|
end
|
46
49
|
|
47
|
-
platforms :mri_19 do
|
48
|
-
gem "debugger"
|
49
|
-
end
|
50
|
-
|
51
50
|
platforms :ruby do
|
52
51
|
gem "pry-byebug"
|
53
52
|
gem "pry", "~> 0.12.0"
|
54
|
-
gem "rb-readline"
|
55
53
|
end
|
56
54
|
|
57
55
|
if version >= 4.0
|
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Activerecord-Import
|
1
|
+
# Activerecord-Import ![Build Status](https://github.com/zdennis/activerecord-import/actions/workflows/test.yaml/badge.svg)
|
2
2
|
|
3
3
|
Activerecord-Import is a library for bulk inserting data using ActiveRecord.
|
4
4
|
|
@@ -266,11 +266,11 @@ Key | Options | Default | Descrip
|
|
266
266
|
------------------------- | --------------------- | ------------------ | -----------
|
267
267
|
:validate | `true`/`false` | `true` | Whether or not to run `ActiveRecord` validations (uniqueness skipped). This option will always be true when using `import!`.
|
268
268
|
:validate_uniqueness | `true`/`false` | `false` | Whether or not to run uniqueness validations, has potential pitfalls, use with caution (requires `>= v0.27.0`).
|
269
|
-
:validate_with_context | `Symbol` |`:create`/`:update` | Allows passing an ActiveModel validation context for each model. Default is `:create` for new records and `:update` for existing ones.
|
270
|
-
:track_validation_failures| `true`/`false` | `false` | When this is set to true, `failed_instances` will be an array of arrays, with each inner array having the form `[:index_in_dataset, :object_with_errors]`
|
271
|
-
:on_duplicate_key_ignore | `true`/`false` | `false` | Allows skipping records with duplicate keys. See [here](
|
269
|
+
:validate_with_context | `Symbol` |`:create`/`:update` | Allows passing an ActiveModel validation context for each model. Default is `:create` for new records and `:update` for existing ones.
|
270
|
+
:track_validation_failures| `true`/`false` | `false` | When this is set to true, `failed_instances` will be an array of arrays, with each inner array having the form `[:index_in_dataset, :object_with_errors]`
|
271
|
+
:on_duplicate_key_ignore | `true`/`false` | `false` | Allows skipping records with duplicate keys. See [here](#duplicate-key-ignore) for more details.
|
272
272
|
:ignore | `true`/`false` | `false` | Alias for :on_duplicate_key_ignore.
|
273
|
-
:on_duplicate_key_update | :all, `Array`, `Hash` | N/A | Allows upsert logic to be used. See [here](
|
273
|
+
:on_duplicate_key_update | :all, `Array`, `Hash` | N/A | Allows upsert logic to be used. See [here](#duplicate-key-update) for more details.
|
274
274
|
:synchronize | `Array` | N/A | An array of ActiveRecord instances. This synchronizes existing instances in memory with updates from the import.
|
275
275
|
:timestamps | `true`/`false` | `true` | Enables/disables timestamps on imported records.
|
276
276
|
:recursive | `true`/`false` | `false` | Imports has_many/has_one associations (PostgreSQL only).
|
@@ -392,7 +392,7 @@ Book.import books, validate_uniqueness: true
|
|
392
392
|
|
393
393
|
### Return Info
|
394
394
|
|
395
|
-
The `import` method returns a `Result` object that responds to `failed_instances` and `num_inserts`. Additionally, for users of Postgres, there will be two arrays `ids` and `results` that can be accessed
|
395
|
+
The `import` method returns a `Result` object that responds to `failed_instances` and `num_inserts`. Additionally, for users of Postgres, there will be two arrays `ids` and `results` that can be accessed.
|
396
396
|
|
397
397
|
```ruby
|
398
398
|
articles = [
|
@@ -433,7 +433,8 @@ Should you wish to specify those columns, you may use the option `timestamps: fa
|
|
433
433
|
|
434
434
|
However, it is also possible to set just `:created_at` in specific records. In this case despite using `timestamps: true`, `:created_at` will be updated only in records where that field is `nil`. Same rule applies for record associations when enabling the option `recursive: true`.
|
435
435
|
|
436
|
-
If you are using custom time zones, these will be respected when performing imports as well as long as `ActiveRecord::Base.default_timezone` is set, which for practically all Rails apps it is
|
436
|
+
If you are using custom time zones, these will be respected when performing imports as well as long as `ActiveRecord::Base.default_timezone` is set, which for practically all Rails apps it is.
|
437
|
+
NOTE: If you are using ActiveRecord 7.0 or later, please use `ActiveRecord.default_timezone` instead.
|
437
438
|
|
438
439
|
### Callbacks
|
439
440
|
|
@@ -572,7 +573,7 @@ When rubygems pushes the `lib` folder onto the load path a `require` will now fi
|
|
572
573
|
|
573
574
|
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.
|
574
575
|
|
575
|
-
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
|
576
|
+
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 explicitly setting this value within the model. For example:
|
576
577
|
|
577
578
|
```ruby
|
578
579
|
class Post < ActiveRecord::Base
|
@@ -615,13 +616,13 @@ After that, you can run the tests. They run against multiple tests and ActiveRec
|
|
615
616
|
|
616
617
|
This is one example of how to run the tests:
|
617
618
|
|
618
|
-
```
|
619
|
+
```bash
|
619
620
|
rm Gemfile.lock
|
620
|
-
AR_VERSION=
|
621
|
-
AR_VERSION=
|
621
|
+
AR_VERSION=7.0 bundle install
|
622
|
+
AR_VERSION=7.0 bundle exec rake test:postgresql test:sqlite3 test:mysql2
|
622
623
|
```
|
623
624
|
|
624
|
-
Once you have pushed up your changes, you can find your CI results [here](https://
|
625
|
+
Once you have pushed up your changes, you can find your CI results [here](https://github.com/zdennis/activerecord-import/actions).
|
625
626
|
|
626
627
|
## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
|
627
628
|
|
data/Rakefile
CHANGED
data/activerecord-import.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require File.expand_path('../lib/activerecord-import/version', __FILE__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
@@ -16,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.require_paths = ["lib"]
|
17
18
|
gem.version = ActiveRecord::Import::VERSION
|
18
19
|
|
19
|
-
gem.required_ruby_version = ">= 2.
|
20
|
+
gem.required_ruby_version = ">= 2.4.0"
|
20
21
|
|
21
|
-
gem.add_runtime_dependency "activerecord", ">=
|
22
|
+
gem.add_runtime_dependency "activerecord", ">= 4.2"
|
22
23
|
gem.add_development_dependency "rake"
|
23
24
|
end
|
data/benchmarks/benchmark.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require "fileutils"
|
3
5
|
require "active_record"
|
@@ -20,7 +22,11 @@ FileUtils.mkdir_p 'log'
|
|
20
22
|
ActiveRecord::Base.configurations["test"] = YAML.load_file(File.join(benchmark_dir, "../test/database.yml"))[options.adapter]
|
21
23
|
ActiveRecord::Base.logger = Logger.new("log/test.log")
|
22
24
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
23
|
-
ActiveRecord
|
25
|
+
if ActiveRecord.respond_to?(:default_timezone)
|
26
|
+
ActiveRecord.default_timezone = :utc
|
27
|
+
else
|
28
|
+
ActiveRecord::Base.default_timezone = :utc
|
29
|
+
end
|
24
30
|
|
25
31
|
require "activerecord-import"
|
26
32
|
ActiveRecord::Base.establish_connection(:test)
|
data/benchmarks/lib/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
require 'ostruct'
|
3
5
|
|
@@ -8,7 +10,7 @@ require 'ostruct'
|
|
8
10
|
# * t - the table types to test. ie: myisam, innodb, memory, temporary, etc.
|
9
11
|
#
|
10
12
|
module BenchmarkOptionParser
|
11
|
-
BANNER = "Usage: ruby #{$0} [options]\nSee ruby #{$0} -h for more options."
|
13
|
+
BANNER = "Usage: ruby #{$0} [options]\nSee ruby #{$0} -h for more options."
|
12
14
|
|
13
15
|
def self.print_banner
|
14
16
|
puts BANNER
|
data/benchmarks/lib/float.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'erb'
|
2
4
|
|
3
5
|
module OutputToHTML
|
4
|
-
TEMPLATE_HEADER = <<"EOT"
|
6
|
+
TEMPLATE_HEADER = <<"EOT"
|
5
7
|
<div>
|
6
8
|
All times are rounded to the nearest thousandth for display purposes. Speedups next to each time are computed
|
7
9
|
before any rounding occurs. Also, all speedup calculations are computed by comparing a given time against
|
@@ -9,7 +11,7 @@ module OutputToHTML
|
|
9
11
|
</div>
|
10
12
|
EOT
|
11
13
|
|
12
|
-
TEMPLATE = <<"EOT"
|
14
|
+
TEMPLATE = <<"EOT"
|
13
15
|
<style>
|
14
16
|
td#benchmarkTitle {
|
15
17
|
border: 1px solid black;
|
data/gemfiles/4.2.gemfile
CHANGED
data/gemfiles/5.0.gemfile
CHANGED
data/gemfiles/5.1.gemfile
CHANGED
data/gemfiles/5.2.gemfile
CHANGED
data/gemfiles/6.0.gemfile
CHANGED
data/gemfiles/6.1.gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
require "activerecord-import/adapters/mysql_adapter"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
require "active_record/connection_adapters/mysql2_adapter"
|
4
|
+
require "activerecord-import/adapters/mysql2_adapter"
|
5
|
+
|
6
|
+
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
7
|
+
include ActiveRecord::Import::Mysql2Adapter
|
6
8
|
end
|