activerecord-import 1.2.0 → 1.5.0
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 +51 -11
- data/.rubocop.yml +74 -8
- data/.rubocop_todo.yml +6 -16
- data/Brewfile +3 -1
- data/CHANGELOG.md +37 -0
- data/Gemfile +8 -10
- data/README.markdown +14 -11
- data/Rakefile +2 -0
- data/activerecord-import.gemspec +4 -3
- data/benchmarks/benchmark.rb +10 -4
- data/benchmarks/lib/base.rb +4 -2
- data/benchmarks/lib/cli_parser.rb +4 -2
- 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 +2 -0
- 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 +8 -5
- 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 +27 -19
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +66 -47
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +36 -30
- data/lib/activerecord-import/base.rb +3 -1
- data/lib/activerecord-import/import.rb +85 -44
- 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 +3 -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/import_test.rb +26 -1
- data/test/jdbcmysql/import_test.rb +5 -3
- data/test/jdbcpostgresql/import_test.rb +4 -2
- data/test/jdbcsqlite3/import_test.rb +4 -2
- data/test/makara_postgis/import_test.rb +4 -2
- 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 +3 -0
- data/test/models/book.rb +2 -0
- data/test/models/car.rb +2 -0
- data/test/models/card.rb +2 -0
- data/test/models/chapter.rb +2 -0
- data/test/models/customer.rb +8 -0
- data/test/models/deck.rb +2 -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 +2 -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 +7 -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 +5 -3
- data/test/mysql2_makara/import_test.rb +5 -3
- data/test/mysqlspatial2/import_test.rb +5 -3
- data/test/postgis/import_test.rb +4 -2
- data/test/postgresql/import_test.rb +4 -2
- data/test/schema/generic_schema.rb +20 -0
- data/test/schema/jdbcpostgresql_schema.rb +3 -1
- data/test/schema/mysql2_schema.rb +2 -0
- data/test/schema/postgis_schema.rb +3 -1
- 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 +4 -2
- 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 +41 -10
- 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 +21 -5
- data/test/value_sets_bytes_parser_test.rb +3 -1
- data/test/value_sets_records_parser_test.rb +3 -1
- metadata +16 -12
- 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: 866dd09466fbda981329e13916e89986cb47d65259f0889b8a3b53aeca1aee32
|
4
|
+
data.tar.gz: 258a0d2fc34bbb928500e2f8a83df4f5bdc8901c25e2e123a569c56d587d3f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989562e1fb64d669a96211c6b80df5b89d8a43aa38575ec6706d0633b405983a63849bd5fb78d4031ed7e4b2c239192f62d4b3d9e720f4c474cd3801600d11ef
|
7
|
+
data.tar.gz: 22e6ccbb750bb7851930d98c2b90f496c759d35503c8c1e58b841f4a928a283c486caec3f22cb57e6948b6960e6fff2a598499f0670f59b281e321dded20c183
|
data/.github/workflows/test.yaml
CHANGED
@@ -20,16 +20,43 @@ jobs:
|
|
20
20
|
fail-fast: false
|
21
21
|
matrix:
|
22
22
|
ruby:
|
23
|
-
- 2
|
23
|
+
- 3.2
|
24
24
|
env:
|
25
|
+
- AR_VERSION: '7.0'
|
26
|
+
RUBYOPT: --enable-frozen-string-literal
|
25
27
|
- AR_VERSION: 6.1
|
26
|
-
|
27
|
-
- AR_VERSION: 5.2
|
28
|
-
- AR_VERSION: 5.1
|
28
|
+
RUBYOPT: --enable-frozen-string-literal
|
29
29
|
include:
|
30
|
+
- ruby: 3.1
|
31
|
+
env:
|
32
|
+
AR_VERSION: '7.0'
|
33
|
+
- ruby: 3.1
|
34
|
+
env:
|
35
|
+
AR_VERSION: 6.1
|
36
|
+
- ruby: '3.0'
|
37
|
+
env:
|
38
|
+
AR_VERSION: '7.0'
|
39
|
+
- ruby: '3.0'
|
40
|
+
env:
|
41
|
+
AR_VERSION: 6.1
|
42
|
+
- ruby: 2.7
|
43
|
+
env:
|
44
|
+
AR_VERSION: '7.0'
|
45
|
+
- ruby: 2.7
|
46
|
+
env:
|
47
|
+
AR_VERSION: 6.1
|
48
|
+
- ruby: 2.7
|
49
|
+
env:
|
50
|
+
AR_VERSION: '6.0'
|
51
|
+
- ruby: 2.6
|
52
|
+
env:
|
53
|
+
AR_VERSION: 5.2
|
54
|
+
- ruby: 2.6
|
55
|
+
env:
|
56
|
+
AR_VERSION: 5.1
|
30
57
|
- ruby: 2.4
|
31
58
|
env:
|
32
|
-
AR_VERSION: 5.0
|
59
|
+
AR_VERSION: '5.0'
|
33
60
|
- ruby: 2.4
|
34
61
|
env:
|
35
62
|
AR_VERSION: 4.2
|
@@ -42,9 +69,7 @@ jobs:
|
|
42
69
|
- uses: ruby/setup-ruby@v1
|
43
70
|
with:
|
44
71
|
ruby-version: ${{ matrix.ruby }}
|
45
|
-
|
46
|
-
if: ${{ matrix.ruby == '2.3' }}
|
47
|
-
run: echo "BUNDLER_VERSION=1.17.3" >> $GITHUB_ENV
|
72
|
+
bundler-cache: true
|
48
73
|
- name: Set up databases
|
49
74
|
run: |
|
50
75
|
sudo /etc/init.d/mysql start
|
@@ -56,18 +81,33 @@ jobs:
|
|
56
81
|
cp test/github/database.yml test/database.yml
|
57
82
|
env:
|
58
83
|
PGPASSWORD: postgres
|
59
|
-
- name:
|
60
|
-
run : AR_VERSION=${{ env.AR_VERSION }} bundle install
|
61
|
-
- name: Run tests
|
84
|
+
- name: Run tests with mysql2
|
62
85
|
run: |
|
63
86
|
bundle exec rake test:mysql2
|
64
87
|
bundle exec rake test:mysql2_makara
|
65
88
|
bundle exec rake test:mysql2spatial
|
89
|
+
- name: Run tests with postgresql
|
90
|
+
run: |
|
66
91
|
bundle exec rake test:postgis
|
67
92
|
bundle exec rake test:postgresql
|
68
93
|
bundle exec rake test:postgresql_makara
|
94
|
+
- name: Run tests with seamless_database_pool
|
95
|
+
run: |
|
69
96
|
bundle exec rake test:seamless_database_pool
|
97
|
+
if: ${{ matrix.ruby < '3.0' }}
|
98
|
+
- name: Run tests with sqlite
|
99
|
+
run: |
|
70
100
|
bundle exec rake test:spatialite
|
71
101
|
bundle exec rake test:sqlite3
|
102
|
+
lint:
|
103
|
+
runs-on: ubuntu-latest
|
104
|
+
env:
|
105
|
+
AR_VERSION: '7.0'
|
106
|
+
steps:
|
107
|
+
- uses: actions/checkout@v2
|
108
|
+
- uses: ruby/setup-ruby@v1
|
109
|
+
with:
|
110
|
+
ruby-version: 2.7
|
111
|
+
bundler-cache: true
|
72
112
|
- name: Run Rubocop
|
73
113
|
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/ArgumentAlignment:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Layout/ParameterAlignment:
|
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/HeredocIndentation:
|
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/MethodParameterName:
|
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/.rubocop_todo.yml
CHANGED
@@ -1,36 +1,26 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2023-02-15 00:58:14 UTC using RuboCop version 1.45.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 2
|
10
|
-
Lint/HandleExceptions:
|
11
|
-
Exclude:
|
12
|
-
- 'lib/activerecord-import/base.rb'
|
13
|
-
- 'test/import_test.rb'
|
14
|
-
|
15
9
|
# Offense count: 2
|
16
10
|
Lint/RescueException:
|
17
11
|
Exclude:
|
18
12
|
- 'benchmarks/lib/cli_parser.rb'
|
19
13
|
- 'test/import_test.rb'
|
20
14
|
|
21
|
-
# Offense count:
|
22
|
-
#
|
23
|
-
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
15
|
+
# Offense count: 3
|
16
|
+
# This cop supports safe autocorrection (--autocorrect).
|
17
|
+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
|
24
18
|
Lint/UnusedMethodArgument:
|
25
19
|
Exclude:
|
26
20
|
- 'lib/activerecord-import/adapters/postgresql_adapter.rb'
|
27
21
|
- 'lib/activerecord-import/import.rb'
|
28
22
|
|
29
23
|
# Offense count: 2
|
30
|
-
|
31
|
-
# Configuration parameters: Keywords.
|
32
|
-
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW
|
33
|
-
Style/CommentAnnotation:
|
24
|
+
Style/CombinableLoops:
|
34
25
|
Exclude:
|
35
|
-
- '
|
36
|
-
- 'lib/activerecord-import/import.rb'
|
26
|
+
- 'test/support/shared_examples/recursive_import.rb'
|
data/Brewfile
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,40 @@
|
|
1
|
+
## Changes in 1.5.0
|
2
|
+
|
3
|
+
### New Features
|
4
|
+
|
5
|
+
* Add Rails 7.1 support. Thanks to @gucki via \##807.
|
6
|
+
* Add support for alias attributes. Thanks to @leonidkroka via \##799.
|
7
|
+
|
8
|
+
### Fixes
|
9
|
+
|
10
|
+
* Support for multi-byte column names when splitting queries. Thanks to @TakuyaKurimoto via \##801.
|
11
|
+
* Fix issue with track_validation_failures when import models. Thanks to @OtaYohihiro via \##798.
|
12
|
+
|
13
|
+
## Changes in 1.4.1
|
14
|
+
|
15
|
+
### Fixes
|
16
|
+
|
17
|
+
* Fix importing models that have required belongs_to associations and use composite primary keys. Thanks to @thoughtbot-summer via \##783.
|
18
|
+
|
19
|
+
## Changes in 1.4.0
|
20
|
+
|
21
|
+
### New Features
|
22
|
+
|
23
|
+
* Enable compatibility with frozen string literals. Thanks to @desheikh via \##760.
|
24
|
+
|
25
|
+
## Changes in 1.3.0
|
26
|
+
|
27
|
+
### Fixes
|
28
|
+
|
29
|
+
* Ensure correct timestamp values are returned for models after insert. Thanks to @kos1kov via \##756.
|
30
|
+
* Restore database_version method to public scope. Thanks to @beauraF via \##753.
|
31
|
+
|
32
|
+
### New Features
|
33
|
+
|
34
|
+
* Add support for ActiveRecord 7.0. Thanks to @nickhammond, @ryanwood, @jkowens via \##749 and \##752.
|
35
|
+
* Add support for compound foreign keys. Thanks to @Uladzimiro via \##750.
|
36
|
+
* Add support for :recursive combined with on_duplicate_key_update: :all. Thanks to @deathwish via \##746.
|
37
|
+
|
1
38
|
## Changes in 1.2.0
|
2
39
|
|
3
40
|
### Fixes
|
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'
|
18
|
+
gem 'rubocop'
|
17
19
|
gem 'rake'
|
18
20
|
end
|
19
21
|
|
@@ -22,11 +24,12 @@ 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
|
29
|
-
gem
|
32
|
+
gem "jdbc-mysql"
|
30
33
|
gem "jdbc-postgres"
|
31
34
|
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3"
|
32
35
|
gem "activerecord-jdbcmysql-adapter", "~> 1.3"
|
@@ -37,21 +40,16 @@ end
|
|
37
40
|
gem "factory_bot"
|
38
41
|
gem "timecop"
|
39
42
|
gem "chronic"
|
40
|
-
gem "mocha", "~> 1.
|
43
|
+
gem "mocha", "~> 2.1.0"
|
41
44
|
|
42
45
|
# Debugging
|
43
46
|
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
|
-
gem "pry", "~> 0.
|
54
|
-
gem "rb-readline"
|
52
|
+
gem "pry", "~> 0.14.0"
|
55
53
|
end
|
56
54
|
|
57
55
|
if version >= 4.0
|
data/README.markdown
CHANGED
@@ -245,8 +245,8 @@ Book.import columns, books, batch_size: 2, batch_progress: my_proc
|
|
245
245
|
|
246
246
|
#### Recursive
|
247
247
|
|
248
|
-
|
249
|
-
hashes or arrays as recursive inputs.
|
248
|
+
> **Note**
|
249
|
+
> This only works with PostgreSQL and ActiveRecord objects. This won't work with hashes or arrays as recursive inputs.
|
250
250
|
|
251
251
|
Assume that Books <code>has_many</code> Reviews.
|
252
252
|
|
@@ -268,9 +268,9 @@ Key | Options | Default | Descrip
|
|
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
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
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](
|
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).
|
@@ -433,7 +433,9 @@ 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**
|
438
|
+
> If you are using ActiveRecord 7.0 or later, please use `ActiveRecord.default_timezone` instead.
|
437
439
|
|
438
440
|
### Callbacks
|
439
441
|
|
@@ -505,7 +507,8 @@ This allows an external gem to dynamically add an adapter without the need to ad
|
|
505
507
|
|
506
508
|
### Requiring
|
507
509
|
|
508
|
-
Note
|
510
|
+
> **Note**
|
511
|
+
> These instructions will only work if you are using version 0.2.0 or higher.
|
509
512
|
|
510
513
|
#### Autoloading via Bundler
|
511
514
|
|
@@ -572,7 +575,7 @@ When rubygems pushes the `lib` folder onto the load path a `require` will now fi
|
|
572
575
|
|
573
576
|
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
577
|
|
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
|
578
|
+
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
579
|
|
577
580
|
```ruby
|
578
581
|
class Post < ActiveRecord::Base
|
@@ -615,13 +618,13 @@ After that, you can run the tests. They run against multiple tests and ActiveRec
|
|
615
618
|
|
616
619
|
This is one example of how to run the tests:
|
617
620
|
|
618
|
-
```
|
621
|
+
```bash
|
619
622
|
rm Gemfile.lock
|
620
|
-
AR_VERSION=
|
621
|
-
AR_VERSION=
|
623
|
+
AR_VERSION=7.0 bundle install
|
624
|
+
AR_VERSION=7.0 bundle exec rake test:postgresql test:sqlite3 test:mysql2
|
622
625
|
```
|
623
626
|
|
624
|
-
Once you have pushed up your changes, you can find your CI results [here](https://
|
627
|
+
Once you have pushed up your changes, you can find your CI results [here](https://github.com/zdennis/activerecord-import/actions).
|
625
628
|
|
626
629
|
## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
|
627
630
|
|
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)
|
@@ -35,7 +41,7 @@ require File.join(benchmark_dir, "../test/schema/generic_schema")
|
|
35
41
|
adapter_schema = File.join(benchmark_dir, "schema/#{options.adapter}_schema.rb")
|
36
42
|
require adapter_schema if File.exist?(adapter_schema)
|
37
43
|
|
38
|
-
Dir[File.dirname(__FILE__)
|
44
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].sort.each { |file| require file }
|
39
45
|
|
40
46
|
require File.join( benchmark_dir, 'lib', "#{options.adapter}_benchmark" )
|
41
47
|
|
@@ -47,8 +53,8 @@ else
|
|
47
53
|
end
|
48
54
|
|
49
55
|
letter = options.adapter[0].chr
|
50
|
-
clazz_str = letter.upcase + options.adapter[1
|
51
|
-
clazz = Object.const_get( clazz_str
|
56
|
+
clazz_str = letter.upcase + options.adapter[1..].downcase
|
57
|
+
clazz = Object.const_get( "#{clazz_str}Benchmark" )
|
52
58
|
|
53
59
|
benchmarks = []
|
54
60
|
options.number_of_objects.each do |num|
|
data/benchmarks/lib/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class BenchmarkBase
|
2
4
|
attr_reader :results
|
3
5
|
|
@@ -25,11 +27,11 @@ class BenchmarkBase
|
|
25
27
|
# An OpenStruct object with the following attributes:
|
26
28
|
# * description - the description of the benchmark ran
|
27
29
|
# * tms - a Benchmark::Tms containing the results of the benchmark
|
28
|
-
def bm( description )
|
30
|
+
def bm( description, &block )
|
29
31
|
tms = nil
|
30
32
|
puts "Benchmarking #{description}"
|
31
33
|
|
32
|
-
Benchmark.bm { |x| tms = x.report
|
34
|
+
Benchmark.bm { |x| tms = x.report(&block) }
|
33
35
|
delete_all
|
34
36
|
failed = false
|
35
37
|
|
@@ -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
|
@@ -27,7 +29,7 @@ module BenchmarkOptionParser
|
|
27
29
|
print_valid_table_types( options, prefix: " " )
|
28
30
|
end
|
29
31
|
|
30
|
-
# TODO IMPLEMENT THIS
|
32
|
+
# TODO: IMPLEMENT THIS
|
31
33
|
def self.print_valid_table_types( options, hsh = { prefix: '' } )
|
32
34
|
if !options.table_types.keys.empty?
|
33
35
|
options.table_types.keys.sort.each { |type| puts hsh[:prefix].to_s + type.to_s }
|
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