activerecord-import 1.3.0 → 1.4.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 +39 -10
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -6
- data/README.markdown +7 -6
- data/benchmarks/benchmark.rb +5 -1
- data/gemfiles/7.0.gemfile +1 -1
- data/lib/activerecord-import/adapters/mysql_adapter.rb +1 -1
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +4 -4
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +4 -4
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +5 -1
- data/test/support/postgresql/import_examples.rb +1 -1
- data/test/test_helper.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71623b61f085adce5254fc92ae524f595594cb5a960bb4bf0cb46d961ca9d203
|
4
|
+
data.tar.gz: ce2200678685afd85dc0a887d967bae7e2e4220942ab2f8fc34bb949b8f5a31b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71bdd79b977164223d77c77ec796ac3914124318bb377c8aa044bc8085d0f7ba9536e35b99b6a670b0a4c825e4dfe49aef5a10626b92109b2ce7dd8cd529dbb1
|
7
|
+
data.tar.gz: 89db7ca7f321a473391d2083a2dc6cb4fe8614069441c2a16601a0a3e4ab848e889eafba67b53fc2042d60b7095aab50926f4795d07930c0c90820527f07c28c
|
data/.github/workflows/test.yaml
CHANGED
@@ -20,12 +20,28 @@ jobs:
|
|
20
20
|
fail-fast: false
|
21
21
|
matrix:
|
22
22
|
ruby:
|
23
|
-
-
|
23
|
+
- 3.1
|
24
24
|
env:
|
25
|
-
- AR_VERSION: 7.0
|
25
|
+
- AR_VERSION: '7.0'
|
26
|
+
RUBYOPT: --enable-frozen-string-literal
|
26
27
|
- AR_VERSION: 6.1
|
27
|
-
|
28
|
+
RUBYOPT: --enable-frozen-string-literal
|
28
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'
|
29
45
|
- ruby: 2.6
|
30
46
|
env:
|
31
47
|
AR_VERSION: 5.2
|
@@ -34,7 +50,7 @@ jobs:
|
|
34
50
|
AR_VERSION: 5.1
|
35
51
|
- ruby: 2.4
|
36
52
|
env:
|
37
|
-
AR_VERSION: 5.0
|
53
|
+
AR_VERSION: '5.0'
|
38
54
|
- ruby: 2.4
|
39
55
|
env:
|
40
56
|
AR_VERSION: 4.2
|
@@ -47,9 +63,7 @@ jobs:
|
|
47
63
|
- uses: ruby/setup-ruby@v1
|
48
64
|
with:
|
49
65
|
ruby-version: ${{ matrix.ruby }}
|
50
|
-
|
51
|
-
if: ${{ matrix.ruby == '2.3' }}
|
52
|
-
run: echo "BUNDLER_VERSION=1.17.3" >> $GITHUB_ENV
|
66
|
+
bundler-cache: true
|
53
67
|
- name: Set up databases
|
54
68
|
run: |
|
55
69
|
sudo /etc/init.d/mysql start
|
@@ -61,18 +75,33 @@ jobs:
|
|
61
75
|
cp test/github/database.yml test/database.yml
|
62
76
|
env:
|
63
77
|
PGPASSWORD: postgres
|
64
|
-
- name:
|
65
|
-
run : AR_VERSION=${{ env.AR_VERSION }} bundle install
|
66
|
-
- name: Run tests
|
78
|
+
- name: Run tests with mysql2
|
67
79
|
run: |
|
68
80
|
bundle exec rake test:mysql2
|
69
81
|
bundle exec rake test:mysql2_makara
|
70
82
|
bundle exec rake test:mysql2spatial
|
83
|
+
- name: Run tests with postgresql
|
84
|
+
run: |
|
71
85
|
bundle exec rake test:postgis
|
72
86
|
bundle exec rake test:postgresql
|
73
87
|
bundle exec rake test:postgresql_makara
|
88
|
+
- name: Run tests with seamless_database_pool
|
89
|
+
run: |
|
74
90
|
bundle exec rake test:seamless_database_pool
|
91
|
+
if: ${{ matrix.ruby < '3.0' }}
|
92
|
+
- name: Run tests with sqlite
|
93
|
+
run: |
|
75
94
|
bundle exec rake test:spatialite
|
76
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
|
77
106
|
- name: Run Rubocop
|
78
107
|
run: bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -22,7 +22,8 @@ platforms :ruby do
|
|
22
22
|
gem "mysql2", "~> #{mysql2_version}"
|
23
23
|
gem "pg", "~> #{pg_version}"
|
24
24
|
gem "sqlite3", "~> #{sqlite3_version}"
|
25
|
-
|
25
|
+
# seamless_database_pool requires Ruby ~> 2.0
|
26
|
+
gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
|
26
27
|
end
|
27
28
|
|
28
29
|
platforms :jruby do
|
@@ -44,14 +45,9 @@ platforms :jruby do
|
|
44
45
|
gem "ruby-debug", "= 0.10.4"
|
45
46
|
end
|
46
47
|
|
47
|
-
platforms :mri_19 do
|
48
|
-
gem "debugger"
|
49
|
-
end
|
50
|
-
|
51
48
|
platforms :ruby do
|
52
49
|
gem "pry-byebug"
|
53
50
|
gem "pry", "~> 0.12.0"
|
54
|
-
gem "rb-readline"
|
55
51
|
end
|
56
52
|
|
57
53
|
if version >= 4.0
|
data/README.markdown
CHANGED
@@ -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/benchmarks/benchmark.rb
CHANGED
@@ -20,7 +20,11 @@ FileUtils.mkdir_p 'log'
|
|
20
20
|
ActiveRecord::Base.configurations["test"] = YAML.load_file(File.join(benchmark_dir, "../test/database.yml"))[options.adapter]
|
21
21
|
ActiveRecord::Base.logger = Logger.new("log/test.log")
|
22
22
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
23
|
-
ActiveRecord
|
23
|
+
if ActiveRecord.respond_to?(:default_timezone)
|
24
|
+
ActiveRecord.default_timezone = :utc
|
25
|
+
else
|
26
|
+
ActiveRecord::Base.default_timezone = :utc
|
27
|
+
end
|
24
28
|
|
25
29
|
require "activerecord-import"
|
26
30
|
ActiveRecord::Base.establish_connection(:test)
|
data/gemfiles/7.0.gemfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
gem 'activerecord', '~> 7.0.0
|
1
|
+
gem 'activerecord', '~> 7.0.0'
|
@@ -82,7 +82,7 @@ module ActiveRecord::Import::MysqlAdapter
|
|
82
82
|
# Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
|
83
83
|
# in +args+.
|
84
84
|
def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
|
85
|
-
sql = ' ON DUPLICATE KEY UPDATE '
|
85
|
+
sql = ' ON DUPLICATE KEY UPDATE '.dup
|
86
86
|
arg = args.first
|
87
87
|
locking_column = args.last
|
88
88
|
if arg.is_a?( Array )
|
@@ -123,7 +123,7 @@ module ActiveRecord::Import::PostgreSQLAdapter
|
|
123
123
|
arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
|
124
124
|
return unless arg.is_a?( Hash )
|
125
125
|
|
126
|
-
sql = ' ON CONFLICT '
|
126
|
+
sql = ' ON CONFLICT '.dup
|
127
127
|
conflict_target = sql_for_conflict_target( arg )
|
128
128
|
|
129
129
|
columns = arg.fetch( :columns, [] )
|
@@ -179,9 +179,9 @@ module ActiveRecord::Import::PostgreSQLAdapter
|
|
179
179
|
if constraint_name.present?
|
180
180
|
"ON CONSTRAINT #{constraint_name} "
|
181
181
|
elsif conflict_target.present?
|
182
|
-
'('
|
183
|
-
|
184
|
-
|
182
|
+
sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
|
183
|
+
sql += "WHERE #{index_predicate} " if index_predicate
|
184
|
+
sql
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
@@ -97,7 +97,7 @@ module ActiveRecord::Import::SQLite3Adapter
|
|
97
97
|
arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
|
98
98
|
return unless arg.is_a?( Hash )
|
99
99
|
|
100
|
-
sql = ' ON CONFLICT '
|
100
|
+
sql = ' ON CONFLICT '.dup
|
101
101
|
conflict_target = sql_for_conflict_target( arg )
|
102
102
|
|
103
103
|
columns = arg.fetch( :columns, [] )
|
@@ -150,9 +150,9 @@ module ActiveRecord::Import::SQLite3Adapter
|
|
150
150
|
conflict_target = args[:conflict_target]
|
151
151
|
index_predicate = args[:index_predicate]
|
152
152
|
if conflict_target.present?
|
153
|
-
'('
|
154
|
-
|
155
|
-
|
153
|
+
sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
|
154
|
+
sql += "WHERE #{index_predicate} " if index_predicate
|
155
|
+
sql
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
data/test/import_test.rb
CHANGED
@@ -555,7 +555,11 @@ describe "#import" do
|
|
555
555
|
context "when the timestamps columns are present" do
|
556
556
|
setup do
|
557
557
|
@existing_book = Book.create(title: "Fell", author_name: "Curry", publisher: "Bayer", created_at: 2.years.ago.utc, created_on: 2.years.ago.utc, updated_at: 2.years.ago.utc, updated_on: 2.years.ago.utc)
|
558
|
-
ActiveRecord
|
558
|
+
if ActiveRecord.respond_to?(:default_timezone)
|
559
|
+
ActiveRecord.default_timezone = :utc
|
560
|
+
else
|
561
|
+
ActiveRecord::Base.default_timezone = :utc
|
562
|
+
end
|
559
563
|
Timecop.freeze(time) do
|
560
564
|
assert_difference "Book.count", +2 do
|
561
565
|
Book.import %w(title author_name publisher created_at created_on updated_at updated_on), [["LDAP", "Big Bird", "Del Rey", nil, nil, nil, nil], [@existing_book.title, @existing_book.author_name, @existing_book.publisher, @existing_book.created_at, @existing_book.created_on, @existing_book.updated_at, @existing_book.updated_on]]
|
@@ -281,7 +281,7 @@ def should_support_postgresql_import_functionality
|
|
281
281
|
end
|
282
282
|
|
283
283
|
describe "with binary field" do
|
284
|
-
let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".force_encoding('ASCII-8BIT') }
|
284
|
+
let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".dup.force_encoding('ASCII-8BIT') }
|
285
285
|
it "imports the correct values for binary fields" do
|
286
286
|
alarms = [Alarm.new(device_id: 1, alarm_type: 1, status: 1, secret_key: binary_value)]
|
287
287
|
assert_difference "Alarm.count", +1 do
|
data/test/test_helper.rb
CHANGED
@@ -51,14 +51,22 @@ ActiveRecord::Base.logger = Logger.new("log/test.log")
|
|
51
51
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
52
52
|
|
53
53
|
if ENV['AR_VERSION'].to_f >= 6.0
|
54
|
-
yaml_config =
|
54
|
+
yaml_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.2.1')
|
55
|
+
YAML.safe_load_file(test_dir.join("database.yml"), aliases: true)[adapter]
|
56
|
+
else
|
57
|
+
YAML.load_file(test_dir.join("database.yml"))[adapter]
|
58
|
+
end
|
55
59
|
config = ActiveRecord::DatabaseConfigurations::HashConfig.new("test", adapter, yaml_config)
|
56
60
|
ActiveRecord::Base.configurations.configurations << config
|
57
61
|
else
|
58
62
|
ActiveRecord::Base.configurations["test"] = YAML.load_file(test_dir.join("database.yml"))[adapter]
|
59
63
|
end
|
60
64
|
|
61
|
-
ActiveRecord
|
65
|
+
if ActiveRecord.respond_to?(:default_timezone)
|
66
|
+
ActiveRecord.default_timezone = :utc
|
67
|
+
else
|
68
|
+
ActiveRecord::Base.default_timezone = :utc
|
69
|
+
end
|
62
70
|
|
63
71
|
require "activerecord-import"
|
64
72
|
ActiveRecord::Base.establish_connection :test
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|