activerecord-import 1.4.1 → 1.8.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 +53 -13
- data/.gitignore +4 -0
- data/.rubocop.yml +7 -4
- data/.rubocop_todo.yml +10 -16
- data/CHANGELOG.md +48 -1
- data/Dockerfile +23 -0
- data/Gemfile +15 -7
- data/README.markdown +44 -5
- data/Rakefile +1 -0
- data/activerecord-import.gemspec +4 -0
- data/benchmarks/benchmark.rb +3 -3
- data/benchmarks/lib/base.rb +2 -2
- data/benchmarks/lib/cli_parser.rb +2 -2
- data/docker-compose.yml +34 -0
- data/gemfiles/7.1.gemfile +3 -0
- data/gemfiles/7.2.gemfile +3 -0
- data/lib/activerecord-import/active_record/adapters/trilogy_adapter.rb +8 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +6 -5
- data/lib/activerecord-import/adapters/mysql_adapter.rb +24 -18
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +26 -18
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +29 -23
- data/lib/activerecord-import/adapters/trilogy_adapter.rb +7 -0
- data/lib/activerecord-import/import.rb +63 -28
- data/lib/activerecord-import/value_sets_parser.rb +1 -0
- data/lib/activerecord-import/version.rb +1 -1
- data/lib/activerecord-import.rb +0 -1
- data/test/adapters/trilogy.rb +9 -0
- data/test/database.yml.sample +7 -0
- data/test/github/database.yml +4 -0
- data/test/jdbcmysql/import_test.rb +3 -3
- data/test/jdbcpostgresql/import_test.rb +2 -2
- data/test/jdbcsqlite3/import_test.rb +2 -2
- data/test/makara_postgis/import_test.rb +2 -2
- data/test/models/author.rb +7 -0
- data/test/models/bike_maker.rb +1 -0
- data/test/models/book.rb +5 -2
- data/test/models/composite_book.rb +19 -0
- data/test/models/composite_chapter.rb +9 -0
- data/test/models/customer.rb +14 -4
- data/test/models/order.rb +13 -4
- data/test/models/tag.rb +6 -1
- data/test/models/tag_alias.rb +7 -1
- data/test/models/topic.rb +5 -0
- data/test/models/widget.rb +10 -3
- data/test/mysql2/import_test.rb +3 -3
- data/test/mysql2_makara/import_test.rb +3 -3
- data/test/mysqlspatial2/import_test.rb +3 -3
- data/test/postgis/import_test.rb +2 -2
- data/test/postgresql/import_test.rb +2 -2
- data/test/schema/generic_schema.rb +4 -1
- data/test/schema/jdbcpostgresql_schema.rb +1 -1
- data/test/schema/postgis_schema.rb +1 -1
- data/test/schema/postgresql_schema.rb +35 -4
- data/test/sqlite3/import_test.rb +2 -2
- data/test/support/postgresql/import_examples.rb +12 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +67 -10
- data/test/support/shared_examples/recursive_import.rb +67 -1
- data/test/test_helper.rb +6 -4
- data/test/trilogy/import_test.rb +7 -0
- data/test/value_sets_bytes_parser_test.rb +1 -1
- data/test/value_sets_records_parser_test.rb +1 -1
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 021d7d0d5b653ef01a5ab1aa23b72cca6f46abc65040014ad02fa790976f0189
|
4
|
+
data.tar.gz: a5440146848bc1bfee194681b9bf53f928150936c3c992eaec1299fec2e7c1bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 460961724684bc286a63ff0880ee8279a5a1528cd02ebd28e4694b8d7c39c22f19183f929ecd525de57a5069bf45218428aae47fd96ea5782e7b51a85aee0e1f
|
7
|
+
data.tar.gz: b864f8eb6fc2a074497761813f29aca981ec23daa7ae12164f1b34a08bbad6175025e6a551575ef2f53f7521f13d15de02eccb24f36c2e18dcdb04fdf77e53a7
|
data/.github/workflows/test.yaml
CHANGED
@@ -16,23 +16,65 @@ jobs:
|
|
16
16
|
--health-interval 10s
|
17
17
|
--health-timeout 5s
|
18
18
|
--health-retries 5
|
19
|
+
mysql:
|
20
|
+
image: mysql:5.7
|
21
|
+
ports:
|
22
|
+
- 3306:3306
|
23
|
+
env:
|
24
|
+
MYSQL_ROOT_PASSWORD: root
|
25
|
+
MYSQL_USER: github
|
26
|
+
MYSQL_PASSWORD: github
|
27
|
+
MYSQL_DATABASE: activerecord_import_test
|
28
|
+
options: >-
|
29
|
+
--health-cmd "mysqladmin ping -h localhost"
|
30
|
+
--health-interval 10s
|
31
|
+
--health-timeout 5s
|
32
|
+
--health-retries 5
|
19
33
|
strategy:
|
20
34
|
fail-fast: false
|
21
35
|
matrix:
|
22
36
|
ruby:
|
23
|
-
- 3.
|
37
|
+
- 3.3
|
24
38
|
env:
|
39
|
+
- AR_VERSION: '7.2'
|
40
|
+
RUBYOPT: --enable-frozen-string-literal
|
41
|
+
- AR_VERSION: '7.1'
|
42
|
+
RUBYOPT: --enable-frozen-string-literal
|
25
43
|
- AR_VERSION: '7.0'
|
26
44
|
RUBYOPT: --enable-frozen-string-literal
|
27
45
|
- AR_VERSION: 6.1
|
28
46
|
RUBYOPT: --enable-frozen-string-literal
|
29
47
|
include:
|
48
|
+
- ruby: 3.2
|
49
|
+
env:
|
50
|
+
AR_VERSION: '7.2'
|
51
|
+
- ruby: 3.2
|
52
|
+
env:
|
53
|
+
AR_VERSION: '7.1'
|
54
|
+
- ruby: 3.2
|
55
|
+
env:
|
56
|
+
AR_VERSION: '7.0'
|
57
|
+
- ruby: 3.2
|
58
|
+
env:
|
59
|
+
AR_VERSION: 6.1
|
60
|
+
- ruby: 3.1
|
61
|
+
env:
|
62
|
+
AR_VERSION: '7.1'
|
63
|
+
- ruby: 3.1
|
64
|
+
env:
|
65
|
+
AR_VERSION: '7.0'
|
66
|
+
- ruby: 3.1
|
67
|
+
env:
|
68
|
+
AR_VERSION: 6.1
|
30
69
|
- ruby: '3.0'
|
31
70
|
env:
|
32
71
|
AR_VERSION: '7.0'
|
33
72
|
- ruby: '3.0'
|
34
73
|
env:
|
35
74
|
AR_VERSION: 6.1
|
75
|
+
- ruby: jruby-9.4.5.0
|
76
|
+
env:
|
77
|
+
AR_VERSION: '7.0'
|
36
78
|
- ruby: 2.7
|
37
79
|
env:
|
38
80
|
AR_VERSION: '7.0'
|
@@ -42,28 +84,23 @@ jobs:
|
|
42
84
|
- ruby: 2.7
|
43
85
|
env:
|
44
86
|
AR_VERSION: '6.0'
|
45
|
-
- ruby:
|
87
|
+
- ruby: jruby-9.3.10.0
|
46
88
|
env:
|
47
|
-
AR_VERSION:
|
89
|
+
AR_VERSION: '6.1'
|
48
90
|
- ruby: 2.6
|
49
91
|
env:
|
50
|
-
AR_VERSION: 5.
|
51
|
-
- ruby: 2.4
|
52
|
-
env:
|
53
|
-
AR_VERSION: '5.0'
|
54
|
-
- ruby: 2.4
|
55
|
-
env:
|
56
|
-
AR_VERSION: 4.2
|
92
|
+
AR_VERSION: 5.2
|
57
93
|
runs-on: ubuntu-latest
|
58
94
|
env:
|
59
95
|
AR_VERSION: ${{ matrix.env.AR_VERSION }}
|
60
96
|
DB_DATABASE: activerecord_import_test
|
61
97
|
steps:
|
62
|
-
- uses: actions/checkout@
|
98
|
+
- uses: actions/checkout@v4
|
63
99
|
- uses: ruby/setup-ruby@v1
|
64
100
|
with:
|
65
101
|
ruby-version: ${{ matrix.ruby }}
|
66
102
|
bundler-cache: true
|
103
|
+
rubygems: latest
|
67
104
|
- name: Set up databases
|
68
105
|
run: |
|
69
106
|
sudo /etc/init.d/mysql start
|
@@ -93,15 +130,18 @@ jobs:
|
|
93
130
|
run: |
|
94
131
|
bundle exec rake test:spatialite
|
95
132
|
bundle exec rake test:sqlite3
|
133
|
+
- name: Run trilogy tests
|
134
|
+
if: ${{ matrix.env.AR_VERSION >= '7.0' && !startsWith(matrix.ruby, 'jruby') }}
|
135
|
+
run: bundle exec rake test:trilogy
|
96
136
|
lint:
|
97
137
|
runs-on: ubuntu-latest
|
98
138
|
env:
|
99
139
|
AR_VERSION: '7.0'
|
100
140
|
steps:
|
101
|
-
- uses: actions/checkout@
|
141
|
+
- uses: actions/checkout@v4
|
102
142
|
- uses: ruby/setup-ruby@v1
|
103
143
|
with:
|
104
|
-
ruby-version:
|
144
|
+
ruby-version: 3.0
|
105
145
|
bundler-cache: true
|
106
146
|
- name: Run Rubocop
|
107
147
|
run: bundle exec rubocop
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 3.0.x
|
5
|
+
|
3
6
|
Metrics/AbcSize:
|
4
7
|
Enabled: false
|
5
8
|
|
@@ -66,10 +69,10 @@ Style/SymbolArray:
|
|
66
69
|
Style/TrailingCommaInArrayLiteral:
|
67
70
|
Enabled: false
|
68
71
|
|
69
|
-
Layout/
|
72
|
+
Layout/ArgumentAlignment:
|
70
73
|
Enabled: false
|
71
74
|
|
72
|
-
Layout/
|
75
|
+
Layout/ParameterAlignment:
|
73
76
|
EnforcedStyle: with_fixed_indentation
|
74
77
|
|
75
78
|
Layout/EndAlignment:
|
@@ -81,7 +84,7 @@ Layout/ElseAlignment:
|
|
81
84
|
Layout/EmptyLineAfterGuardClause:
|
82
85
|
Enabled: false
|
83
86
|
|
84
|
-
Layout/
|
87
|
+
Layout/HeredocIndentation:
|
85
88
|
Enabled: false
|
86
89
|
|
87
90
|
Layout/SpaceInsideParens:
|
@@ -102,7 +105,7 @@ Lint/PercentStringArray:
|
|
102
105
|
Naming/HeredocDelimiterNaming:
|
103
106
|
Enabled: false
|
104
107
|
|
105
|
-
Naming/
|
108
|
+
Naming/MethodParameterName:
|
106
109
|
Enabled: false
|
107
110
|
|
108
111
|
Security/YAMLLoad:
|
data/.rubocop_todo.yml
CHANGED
@@ -1,36 +1,30 @@
|
|
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
|
-
|
26
|
+
- 'test/support/shared_examples/recursive_import.rb'
|
27
|
+
|
28
|
+
Naming/FileName:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/activerecord-import.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,55 @@
|
|
1
|
+
## Changes in 1.8.1
|
2
|
+
|
3
|
+
### Fixes
|
4
|
+
|
5
|
+
* Further update for ActiveRecord 7.2 compatibility when running validations. Thanks to @denisahearn via \##847.
|
6
|
+
|
7
|
+
## Changes in 1.8.0
|
8
|
+
|
9
|
+
### New Features
|
10
|
+
|
11
|
+
* Add support for ActiveRecord 7.2 via \##845.
|
12
|
+
|
13
|
+
## Changes in 1.7.0
|
14
|
+
|
15
|
+
### New Features
|
16
|
+
|
17
|
+
* Add support for ActiveRecord 7.1 composite primary keys. Thanks to @fragkakis via \##837.
|
18
|
+
* Add support for upserting associations when doing recursive imports. Thanks to @ramblex via \##778.
|
19
|
+
|
20
|
+
## Changes in 1.6.0
|
21
|
+
|
22
|
+
### New Features
|
23
|
+
|
24
|
+
* Add trilogy adapter support. Thanks to @zmariscal via \##825.
|
25
|
+
|
26
|
+
### Fixes
|
27
|
+
|
28
|
+
* Use the locking_enabled? method provided by activerecord to decide whether the lock field should be updated. Thanks to @dombesz via \##822.
|
29
|
+
|
30
|
+
## Changes in 1.5.1
|
31
|
+
|
32
|
+
### Fixes
|
33
|
+
|
34
|
+
* Stop memoizing schema_columns_hash so dynamic schema changes are picked up. Thanks to @koshigoe via \##812.
|
35
|
+
|
36
|
+
## Changes in 1.5.0
|
37
|
+
|
38
|
+
### New Features
|
39
|
+
|
40
|
+
* Add Rails 7.1 support. Thanks to @gucki via \##807.
|
41
|
+
* Add support for alias attributes. Thanks to @leonidkroka via \##799.
|
42
|
+
|
43
|
+
### Fixes
|
44
|
+
|
45
|
+
* Support for multi-byte column names when splitting queries. Thanks to @TakuyaKurimoto via \##801.
|
46
|
+
* Fix issue with track_validation_failures when import models. Thanks to @OtaYohihiro via \##798.
|
47
|
+
|
1
48
|
## Changes in 1.4.1
|
2
49
|
|
3
50
|
### Fixes
|
4
51
|
|
5
|
-
* Fix importing models that have required belongs_to associations and use composite primary keys. Thanks to @thoughtbot-summer
|
52
|
+
* Fix importing models that have required belongs_to associations and use composite primary keys. Thanks to @thoughtbot-summer via \##783.
|
6
53
|
|
7
54
|
## Changes in 1.4.0
|
8
55
|
|
data/Dockerfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Use the official Ruby 3.2 image as a base image
|
2
|
+
ARG RUBY_VERSION=3.2
|
3
|
+
FROM ruby:${RUBY_VERSION}-bullseye
|
4
|
+
|
5
|
+
# Set the working directory
|
6
|
+
WORKDIR /usr/src/app
|
7
|
+
|
8
|
+
# Install system packages
|
9
|
+
RUN apt-get update -qq && \
|
10
|
+
apt-get install -y default-mysql-client postgresql postgresql-contrib vim && \
|
11
|
+
apt-get clean
|
12
|
+
|
13
|
+
# Set environment variables
|
14
|
+
ENV AR_VERSION=7.0
|
15
|
+
|
16
|
+
# Copy all files
|
17
|
+
COPY . .
|
18
|
+
|
19
|
+
# Move sample database.yml and install gems
|
20
|
+
RUN mv test/database.yml.sample test/database.yml && \
|
21
|
+
bundle install
|
22
|
+
|
23
|
+
CMD ["irb"]
|
data/Gemfile
CHANGED
@@ -15,7 +15,7 @@ pg_version = '0.9'
|
|
15
15
|
pg_version = '1.1' if version >= 6.1
|
16
16
|
|
17
17
|
group :development, :test do
|
18
|
-
gem 'rubocop'
|
18
|
+
gem 'rubocop'
|
19
19
|
gem 'rake'
|
20
20
|
end
|
21
21
|
|
@@ -26,21 +26,29 @@ platforms :ruby do
|
|
26
26
|
gem "sqlite3", "~> #{sqlite3_version}"
|
27
27
|
# seamless_database_pool requires Ruby ~> 2.0
|
28
28
|
gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
|
29
|
+
gem "trilogy" if version >= 6.0
|
30
|
+
if version >= 6.0 && version <= 7.0
|
31
|
+
gem "activerecord-trilogy-adapter"
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
platforms :jruby do
|
32
36
|
gem "jdbc-mysql"
|
33
37
|
gem "jdbc-postgres"
|
34
|
-
gem "activerecord-jdbcsqlite3-adapter"
|
35
|
-
gem "activerecord-jdbcmysql-adapter"
|
36
|
-
gem "activerecord-jdbcpostgresql-adapter"
|
38
|
+
gem "activerecord-jdbcsqlite3-adapter"
|
39
|
+
gem "activerecord-jdbcmysql-adapter"
|
40
|
+
gem "activerecord-jdbcpostgresql-adapter"
|
37
41
|
end
|
38
42
|
|
39
43
|
# Support libs
|
40
|
-
|
44
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0")
|
45
|
+
gem "factory_bot"
|
46
|
+
else
|
47
|
+
gem "factory_bot", "~> 5", "< 6.4.5"
|
48
|
+
end
|
41
49
|
gem "timecop"
|
42
50
|
gem "chronic"
|
43
|
-
gem "mocha", "~> 1.
|
51
|
+
gem "mocha", "~> 2.1.0"
|
44
52
|
|
45
53
|
# Debugging
|
46
54
|
platforms :jruby do
|
@@ -49,7 +57,7 @@ end
|
|
49
57
|
|
50
58
|
platforms :ruby do
|
51
59
|
gem "pry-byebug"
|
52
|
-
gem "pry", "~> 0.
|
60
|
+
gem "pry", "~> 0.14.0"
|
53
61
|
end
|
54
62
|
|
55
63
|
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
|
|
@@ -265,7 +265,7 @@ Book.import books, recursive: true
|
|
265
265
|
Key | Options | Default | Description
|
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
|
-
:validate_uniqueness | `true`/`false` | `false` | Whether or not to run uniqueness validations
|
268
|
+
:validate_uniqueness | `true`/`false` | `false` | Whether or not to run ActiveRecord uniqueness validations. Beware this will incur an sql query per-record (N+1 queries). (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
271
|
:on_duplicate_key_ignore | `true`/`false` | `false` | Allows skipping records with duplicate keys. See [here](#duplicate-key-ignore) for more details.
|
@@ -274,6 +274,7 @@ Key | Options | Default | Descrip
|
|
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).
|
277
|
+
:recursive_on_duplicate_key_update | `Hash` | N/A | Allows upsert logic to be used for recursive associations. The hash key is the association name and the value has the same options as `:on_duplicate_key_update`. See [here](#duplicate-key-update) for more details.
|
277
278
|
:batch_size | `Integer` | total # of records | Max number of records to insert per import
|
278
279
|
:raise_error | `true`/`false` | `false` | Raises an exception at the first invalid record. This means there will not be a result object returned. The `import!` method is a shortcut for this.
|
279
280
|
:all_or_none | `true`/`false` | `false` | Will not import any records if there is a record with validation errors.
|
@@ -364,6 +365,29 @@ book.reload.title # => "Book1" (stayed the same)
|
|
364
365
|
book.reload.author # => "Bob Barker" (changed)
|
365
366
|
```
|
366
367
|
|
368
|
+
PostgreSQL Using partial indexes
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
book = Book.create! title: "Book1", author: "George Orwell", published_at: Time.now
|
372
|
+
book.author = "Bob Barker"
|
373
|
+
|
374
|
+
# in migration
|
375
|
+
execute <<-SQL
|
376
|
+
CREATE INDEX books_published_at_index ON books (published_at) WHERE published_at IS NOT NULL;
|
377
|
+
SQL
|
378
|
+
|
379
|
+
# PostgreSQL version
|
380
|
+
Book.import [book], on_duplicate_key_update: {
|
381
|
+
conflict_target: [:id],
|
382
|
+
index_predicate: "published_at IS NOT NULL",
|
383
|
+
columns: [:author]
|
384
|
+
}
|
385
|
+
|
386
|
+
book.reload.title # => "Book1" (stayed the same)
|
387
|
+
book.reload.author # => "Bob Barker" (changed)
|
388
|
+
book.reload.published_at # => 2017-10-09 (stayed the same)
|
389
|
+
```
|
390
|
+
|
367
391
|
PostgreSQL Using constraints
|
368
392
|
|
369
393
|
```ruby
|
@@ -434,7 +458,8 @@ Should you wish to specify those columns, you may use the option `timestamps: fa
|
|
434
458
|
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
459
|
|
436
460
|
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
|
-
|
461
|
+
> **Note**
|
462
|
+
> If you are using ActiveRecord 7.0 or later, please use `ActiveRecord.default_timezone` instead.
|
438
463
|
|
439
464
|
### Callbacks
|
440
465
|
|
@@ -506,7 +531,8 @@ This allows an external gem to dynamically add an adapter without the need to ad
|
|
506
531
|
|
507
532
|
### Requiring
|
508
533
|
|
509
|
-
Note
|
534
|
+
> **Note**
|
535
|
+
> These instructions will only work if you are using version 0.2.0 or higher.
|
510
536
|
|
511
537
|
#### Autoloading via Bundler
|
512
538
|
|
@@ -624,6 +650,19 @@ AR_VERSION=7.0 bundle exec rake test:postgresql test:sqlite3 test:mysql2
|
|
624
650
|
|
625
651
|
Once you have pushed up your changes, you can find your CI results [here](https://github.com/zdennis/activerecord-import/actions).
|
626
652
|
|
653
|
+
#### Docker Setup
|
654
|
+
|
655
|
+
Before you begin, make sure you have [Docker](https://www.docker.com/products/docker-desktop/) and [Docker Compose](https://docs.docker.com/compose/) installed on your machine. If you don't, you can install both via Homebrew using the following command:
|
656
|
+
|
657
|
+
```bash
|
658
|
+
brew install docker && brew install docker-compose
|
659
|
+
```
|
660
|
+
##### Steps
|
661
|
+
|
662
|
+
1. In your terminal run `docker-compose up --build`
|
663
|
+
1. In another tab/window run `docker-compose exec app bash`
|
664
|
+
1. In that same terminal run the mysql2 test by running `bundle exec rake test:mysql2`
|
665
|
+
|
627
666
|
## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
|
628
667
|
|
629
668
|
You can triage issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to activerecord-import on CodeTriage](https://www.codetriage.com/zdennis/activerecord-import).
|
data/Rakefile
CHANGED
data/activerecord-import.gemspec
CHANGED
@@ -10,6 +10,10 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.homepage = "https://github.com/zdennis/activerecord-import"
|
11
11
|
gem.license = "MIT"
|
12
12
|
|
13
|
+
gem.metadata = {
|
14
|
+
"changelog_uri" => "https://github.com/zdennis/activerecord-import/blob/master/CHANGELOG.md"
|
15
|
+
}
|
16
|
+
|
13
17
|
gem.files = `git ls-files`.split($\)
|
14
18
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
15
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/benchmarks/benchmark.rb
CHANGED
@@ -41,7 +41,7 @@ require File.join(benchmark_dir, "../test/schema/generic_schema")
|
|
41
41
|
adapter_schema = File.join(benchmark_dir, "schema/#{options.adapter}_schema.rb")
|
42
42
|
require adapter_schema if File.exist?(adapter_schema)
|
43
43
|
|
44
|
-
Dir[File.dirname(__FILE__)
|
44
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].sort.each { |file| require file }
|
45
45
|
|
46
46
|
require File.join( benchmark_dir, 'lib', "#{options.adapter}_benchmark" )
|
47
47
|
|
@@ -53,8 +53,8 @@ else
|
|
53
53
|
end
|
54
54
|
|
55
55
|
letter = options.adapter[0].chr
|
56
|
-
clazz_str = letter.upcase + options.adapter[1
|
57
|
-
clazz = Object.const_get( clazz_str
|
56
|
+
clazz_str = letter.upcase + options.adapter[1..].downcase
|
57
|
+
clazz = Object.const_get( "#{clazz_str}Benchmark" )
|
58
58
|
|
59
59
|
benchmarks = []
|
60
60
|
options.number_of_objects.each do |num|
|
data/benchmarks/lib/base.rb
CHANGED
@@ -27,11 +27,11 @@ class BenchmarkBase
|
|
27
27
|
# An OpenStruct object with the following attributes:
|
28
28
|
# * description - the description of the benchmark ran
|
29
29
|
# * tms - a Benchmark::Tms containing the results of the benchmark
|
30
|
-
def bm( description )
|
30
|
+
def bm( description, &block )
|
31
31
|
tms = nil
|
32
32
|
puts "Benchmarking #{description}"
|
33
33
|
|
34
|
-
Benchmark.bm { |x| tms = x.report
|
34
|
+
Benchmark.bm { |x| tms = x.report(&block) }
|
35
35
|
delete_all
|
36
36
|
failed = false
|
37
37
|
|
@@ -10,7 +10,7 @@ require 'ostruct'
|
|
10
10
|
# * t - the table types to test. ie: myisam, innodb, memory, temporary, etc.
|
11
11
|
#
|
12
12
|
module BenchmarkOptionParser
|
13
|
-
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.".freeze
|
14
14
|
|
15
15
|
def self.print_banner
|
16
16
|
puts BANNER
|
@@ -29,7 +29,7 @@ module BenchmarkOptionParser
|
|
29
29
|
print_valid_table_types( options, prefix: " " )
|
30
30
|
end
|
31
31
|
|
32
|
-
# TODO IMPLEMENT THIS
|
32
|
+
# TODO: IMPLEMENT THIS
|
33
33
|
def self.print_valid_table_types( options, hsh = { prefix: '' } )
|
34
34
|
if !options.table_types.keys.empty?
|
35
35
|
options.table_types.keys.sort.each { |type| puts hsh[:prefix].to_s + type.to_s }
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
version: "3.5"
|
2
|
+
|
3
|
+
services:
|
4
|
+
mysql:
|
5
|
+
platform: linux/x86_64
|
6
|
+
image: mysql:5.7
|
7
|
+
volumes:
|
8
|
+
- mysql-data:/var/lib/mysql
|
9
|
+
ports:
|
10
|
+
- "3306:3306"
|
11
|
+
|
12
|
+
postgresql:
|
13
|
+
image: postgres:latest
|
14
|
+
volumes:
|
15
|
+
- postgresql-data:/var/lib/postgresql/data
|
16
|
+
ports:
|
17
|
+
- "5432:5432"
|
18
|
+
|
19
|
+
app:
|
20
|
+
build:
|
21
|
+
context: .
|
22
|
+
environment:
|
23
|
+
DB_HOST: mysql
|
24
|
+
AR_VERSION: 7.0
|
25
|
+
volumes:
|
26
|
+
- .:/usr/src/app
|
27
|
+
depends_on:
|
28
|
+
- mysql
|
29
|
+
- postgresql
|
30
|
+
command: tail -f /dev/null
|
31
|
+
|
32
|
+
volumes:
|
33
|
+
mysql-data:
|
34
|
+
postgresql-data:
|
@@ -9,10 +9,11 @@ module ActiveRecord::Import::AbstractAdapter
|
|
9
9
|
def insert_many( sql, values, _options = {}, *args ) # :nodoc:
|
10
10
|
number_of_inserts = 1
|
11
11
|
|
12
|
-
base_sql, post_sql =
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
base_sql, post_sql = case sql
|
13
|
+
when String
|
14
|
+
[sql, '']
|
15
|
+
when Array
|
16
|
+
[sql.shift, sql.join( ' ' )]
|
16
17
|
end
|
17
18
|
|
18
19
|
sql2insert = base_sql + values.join( ',' ) + post_sql
|
@@ -47,7 +48,7 @@ module ActiveRecord::Import::AbstractAdapter
|
|
47
48
|
post_sql_statements = []
|
48
49
|
|
49
50
|
if supports_on_duplicate_key_update? && options[:on_duplicate_key_update]
|
50
|
-
post_sql_statements << sql_for_on_duplicate_key_update( table_name, options[:on_duplicate_key_update], options[:primary_key], options[:locking_column] )
|
51
|
+
post_sql_statements << sql_for_on_duplicate_key_update( table_name, options[:on_duplicate_key_update], options[:model], options[:primary_key], options[:locking_column] )
|
51
52
|
elsif logger && options[:on_duplicate_key_update]
|
52
53
|
logger.warn "Ignoring on_duplicate_key_update because it is not supported by the database."
|
53
54
|
end
|