activerecord-import 1.4.0 → 1.5.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 +20 -3
- data/.rubocop.yml +74 -8
- data/.rubocop_todo.yml +6 -16
- data/Brewfile +3 -1
- data/CHANGELOG.md +24 -0
- data/Dockerfile +23 -0
- data/Gemfile +8 -6
- data/README.markdown +21 -6
- data/Rakefile +2 -0
- data/activerecord-import.gemspec +2 -1
- data/benchmarks/benchmark.rb +5 -3
- 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/docker-compose.yml +34 -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 +2 -0
- data/gemfiles/7.0.gemfile +3 -0
- data/gemfiles/7.1.gemfile +3 -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 +26 -18
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +63 -42
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +33 -25
- data/lib/activerecord-import/base.rb +3 -1
- data/lib/activerecord-import/import.rb +60 -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 +2 -0
- 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/database.yml.sample +2 -0
- data/test/import_test.rb +21 -0
- 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 +3 -1
- 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 -4
- 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 -4
- 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 +7 -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 +12 -1
- 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 +3 -4
- 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 +40 -1
- 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 +3 -1
- data/test/support/sqlite3/import_examples.rb +2 -1
- data/test/synchronize_test.rb +2 -0
- data/test/test_helper.rb +11 -3
- data/test/value_sets_bytes_parser_test.rb +3 -1
- data/test/value_sets_records_parser_test.rb +3 -1
- metadata +11 -6
data/test/models/widget.rb
CHANGED
data/test/mysql2/import_test.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
4
6
|
|
5
7
|
should_support_mysql_import_functionality
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
4
|
-
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
5
7
|
|
6
8
|
should_support_mysql_import_functionality
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
4
|
-
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
5
7
|
|
6
8
|
should_support_mysql_import_functionality
|
data/test/postgis/import_test.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
3
5
|
|
4
6
|
should_support_postgresql_import_functionality
|
5
7
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
3
5
|
|
4
6
|
should_support_postgresql_import_functionality
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ActiveRecord::Schema.define do
|
2
4
|
create_table :schema_info, force: :cascade do |t|
|
3
|
-
t.integer :version
|
5
|
+
t.integer :version
|
4
6
|
end
|
7
|
+
add_index :schema_info, :version, unique: true
|
8
|
+
|
5
9
|
SchemaInfo.create version: SchemaInfo::VERSION
|
6
10
|
|
7
11
|
create_table :group, force: :cascade do |t|
|
@@ -20,6 +24,7 @@ ActiveRecord::Schema.define do
|
|
20
24
|
t.boolean :approved, default: '1'
|
21
25
|
t.integer :replies_count
|
22
26
|
t.integer :parent_id
|
27
|
+
t.integer :priority, default: 0
|
23
28
|
t.string :type
|
24
29
|
t.datetime :created_at
|
25
30
|
t.datetime :created_on
|
@@ -204,6 +209,12 @@ ActiveRecord::Schema.define do
|
|
204
209
|
PRIMARY KEY (tag_id, publisher_id)
|
205
210
|
);
|
206
211
|
).split.join(' ').strip
|
212
|
+
|
213
|
+
create_table :tag_aliases, force: :cascade do |t|
|
214
|
+
t.integer :tag_id, null: false
|
215
|
+
t.integer :parent_id, null: false
|
216
|
+
t.string :alias, null: false
|
217
|
+
end
|
207
218
|
end
|
208
219
|
|
209
220
|
create_table :customers, force: :cascade do |t|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ActiveRecord::Schema.define do
|
2
4
|
execute('CREATE extension IF NOT EXISTS "hstore";')
|
3
5
|
execute('CREATE extension IF NOT EXISTS "pgcrypto";')
|
@@ -6,10 +8,7 @@ ActiveRecord::Schema.define do
|
|
6
8
|
# create ENUM if it does not exist yet
|
7
9
|
begin
|
8
10
|
execute('CREATE TYPE vendor_type AS ENUM (\'wholesaler\', \'retailer\');')
|
9
|
-
rescue ActiveRecord::StatementInvalid
|
10
|
-
# since PostgreSQL does not support IF NOT EXISTS when creating a TYPE,
|
11
|
-
# rescue the error and check the error class
|
12
|
-
raise unless e.cause.is_a? PG::DuplicateObject
|
11
|
+
rescue ActiveRecord::StatementInvalid
|
13
12
|
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'wholesaler\';')
|
14
13
|
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'retailer\';')
|
15
14
|
end
|
data/test/schema/version.rb
CHANGED
data/test/sqlite3/import_test.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/sqlite3/import_examples")
|
3
5
|
|
4
6
|
should_support_sqlite3_import_functionality
|
data/test/support/assertions.rb
CHANGED
data/test/support/factories.rb
CHANGED
data/test/support/generate.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ActiveSupport::TestCase
|
2
|
-
def Build(*args) # rubocop:disable
|
4
|
+
def Build(*args) # rubocop:disable Naming/MethodName
|
3
5
|
n = args.shift if args.first.is_a?(Numeric)
|
4
6
|
factory = args.shift
|
5
7
|
factory_bot_args = args.shift || {}
|
@@ -13,7 +15,7 @@ class ActiveSupport::TestCase
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
def Generate(*args) # rubocop:disable
|
18
|
+
def Generate(*args) # rubocop:disable Naming/MethodName
|
17
19
|
n = args.shift if args.first.is_a?(Numeric)
|
18
20
|
factory = args.shift
|
19
21
|
factory_bot_args = args.shift || {}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
def should_support_postgresql_import_functionality
|
3
4
|
should_support_recursive_import
|
4
5
|
|
@@ -102,6 +103,8 @@ def should_support_postgresql_import_functionality
|
|
102
103
|
books.first.id.to_s
|
103
104
|
end
|
104
105
|
end
|
106
|
+
let(:true_returning_value) { ENV['AR_VERSION'].to_f >= 5.0 ? true : 't' }
|
107
|
+
let(:false_returning_value) { ENV['AR_VERSION'].to_f >= 5.0 ? false : 'f' }
|
105
108
|
|
106
109
|
it "creates records" do
|
107
110
|
assert_difference("Book.count", +1) { result }
|
@@ -150,6 +153,34 @@ def should_support_postgresql_import_functionality
|
|
150
153
|
end
|
151
154
|
end
|
152
155
|
|
156
|
+
context "when returning is raw sql" do
|
157
|
+
let(:result) { Book.import(books, returning: "title, (xmax = '0') AS inserted") }
|
158
|
+
|
159
|
+
setup { result }
|
160
|
+
|
161
|
+
it "returns ids" do
|
162
|
+
assert_equal [book_id], result.ids
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns specified columns" do
|
166
|
+
assert_equal [['It', true_returning_value]], result.results
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "when returning contains raw sql" do
|
171
|
+
let(:result) { Book.import(books, returning: [:title, "id, (xmax = '0') AS inserted"]) }
|
172
|
+
|
173
|
+
setup { result }
|
174
|
+
|
175
|
+
it "returns ids" do
|
176
|
+
assert_equal [book_id], result.ids
|
177
|
+
end
|
178
|
+
|
179
|
+
it "returns specified columns" do
|
180
|
+
assert_equal [['It', book_id, true_returning_value]], result.results
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
153
184
|
context "setting model attributes" do
|
154
185
|
let(:code) { 'abc' }
|
155
186
|
let(:discount) { 0.10 }
|
@@ -179,6 +210,14 @@ def should_support_postgresql_import_functionality
|
|
179
210
|
assert_equal updated_promotion.discount, discount
|
180
211
|
end
|
181
212
|
end
|
213
|
+
|
214
|
+
context 'returning raw sql' do
|
215
|
+
let(:returning_columns) { [:discount, "(xmax = '0') AS inserted"] }
|
216
|
+
|
217
|
+
it "sets custom model attributes" do
|
218
|
+
assert_equal updated_promotion.inserted, false_returning_value
|
219
|
+
end
|
220
|
+
end
|
182
221
|
end
|
183
222
|
end
|
184
223
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
def should_support_basic_on_duplicate_key_update
|
2
4
|
describe "#import" do
|
3
5
|
extend ActiveSupport::TestCase::ImportAssertions
|
@@ -24,7 +26,7 @@ def should_support_basic_on_duplicate_key_update
|
|
24
26
|
User.import(updated_users, on_duplicate_key_update: [:name])
|
25
27
|
assert User.count == updated_users.length
|
26
28
|
User.all.each_with_index do |user, i|
|
27
|
-
assert_equal user.name, users[i].name
|
29
|
+
assert_equal user.name, "#{users[i].name} Rothschild"
|
28
30
|
assert_equal 1, user.lock_version
|
29
31
|
end
|
30
32
|
end
|
@@ -48,7 +50,7 @@ def should_support_basic_on_duplicate_key_update
|
|
48
50
|
User.import(columns, updated_values, on_duplicate_key_update: [:name])
|
49
51
|
assert User.count == updated_values.length
|
50
52
|
User.all.each_with_index do |user, i|
|
51
|
-
assert_equal user.name, users[i].name
|
53
|
+
assert_equal user.name, "#{users[i].name} Rothschild"
|
52
54
|
assert_equal 1, user.lock_version
|
53
55
|
end
|
54
56
|
end
|
@@ -70,7 +72,7 @@ def should_support_basic_on_duplicate_key_update
|
|
70
72
|
User.import(updated_values, on_duplicate_key_update: [:name])
|
71
73
|
assert User.count == updated_values.length
|
72
74
|
User.all.each_with_index do |user, i|
|
73
|
-
assert_equal user.name, users[i].name
|
75
|
+
assert_equal user.name, "#{users[i].name} Rothschild"
|
74
76
|
assert_equal 1, user.lock_version
|
75
77
|
end
|
76
78
|
updated_values2 = User.all.map do |user|
|
@@ -80,7 +82,7 @@ def should_support_basic_on_duplicate_key_update
|
|
80
82
|
User.import(updated_values2, on_duplicate_key_update: [:name])
|
81
83
|
assert User.count == updated_values2.length
|
82
84
|
User.all.each_with_index do |user, i|
|
83
|
-
assert_equal user.name, users[i].name
|
85
|
+
assert_equal user.name, "#{users[i].name} Rothschild jr."
|
84
86
|
assert_equal 2, user.lock_version
|
85
87
|
end
|
86
88
|
end
|
@@ -102,7 +104,7 @@ def should_support_basic_on_duplicate_key_update
|
|
102
104
|
Account.import(updated_accounts, on_duplicate_key_update: [:id, :name])
|
103
105
|
assert Account.count == updated_accounts.length
|
104
106
|
Account.all.each_with_index do |user, i|
|
105
|
-
assert_equal user.name, accounts[i].name
|
107
|
+
assert_equal user.name, "#{accounts[i].name} Rothschild"
|
106
108
|
assert_equal 1, user.lock
|
107
109
|
end
|
108
110
|
end
|
@@ -126,7 +128,7 @@ def should_support_basic_on_duplicate_key_update
|
|
126
128
|
Account.import(columns, updated_values, on_duplicate_key_update: [:name])
|
127
129
|
assert Account.count == updated_values.length
|
128
130
|
Account.all.each_with_index do |user, i|
|
129
|
-
assert_equal user.name, accounts[i].name
|
131
|
+
assert_equal user.name, "#{accounts[i].name} Rothschild"
|
130
132
|
assert_equal 1, user.lock
|
131
133
|
end
|
132
134
|
end
|
@@ -148,7 +150,7 @@ def should_support_basic_on_duplicate_key_update
|
|
148
150
|
Account.import(updated_values, on_duplicate_key_update: [:name])
|
149
151
|
assert Account.count == updated_values.length
|
150
152
|
Account.all.each_with_index do |user, i|
|
151
|
-
assert_equal user.name, accounts[i].name
|
153
|
+
assert_equal user.name, "#{accounts[i].name} Rothschild"
|
152
154
|
assert_equal 1, user.lock
|
153
155
|
end
|
154
156
|
end
|
@@ -170,10 +172,11 @@ def should_support_basic_on_duplicate_key_update
|
|
170
172
|
Bike::Maker.import(updated_makers, on_duplicate_key_update: [:name])
|
171
173
|
assert Bike::Maker.count == updated_makers.length
|
172
174
|
Bike::Maker.all.each_with_index do |maker, i|
|
173
|
-
assert_equal maker.name, makers[i].name
|
175
|
+
assert_equal maker.name, "#{makers[i].name} bikes"
|
174
176
|
assert_equal 1, maker.lock_version
|
175
177
|
end
|
176
178
|
end
|
179
|
+
|
177
180
|
it 'update the lock_version of models separated by namespaces by array' do
|
178
181
|
makers = [
|
179
182
|
Bike::Maker.new(name: 'Yamaha'),
|
@@ -193,7 +196,7 @@ def should_support_basic_on_duplicate_key_update
|
|
193
196
|
Bike::Maker.import(columns, updated_values, on_duplicate_key_update: [:name])
|
194
197
|
assert Bike::Maker.count == updated_values.length
|
195
198
|
Bike::Maker.all.each_with_index do |maker, i|
|
196
|
-
assert_equal maker.name, makers[i].name
|
199
|
+
assert_equal maker.name, "#{makers[i].name} bikes"
|
197
200
|
assert_equal 1, maker.lock_version
|
198
201
|
end
|
199
202
|
end
|
@@ -215,7 +218,7 @@ def should_support_basic_on_duplicate_key_update
|
|
215
218
|
Bike::Maker.import(updated_values, on_duplicate_key_update: [:name])
|
216
219
|
assert Bike::Maker.count == updated_values.length
|
217
220
|
Bike::Maker.all.each_with_index do |maker, i|
|
218
|
-
assert_equal maker.name, makers[i].name
|
221
|
+
assert_equal maker.name, "#{makers[i].name} bikes"
|
219
222
|
assert_equal 1, maker.lock_version
|
220
223
|
end
|
221
224
|
end
|
@@ -314,6 +317,34 @@ def should_support_basic_on_duplicate_key_update
|
|
314
317
|
should_support_on_duplicate_key_update
|
315
318
|
should_update_fields_mentioned
|
316
319
|
end
|
320
|
+
|
321
|
+
context "using column aliases" do
|
322
|
+
let(:columns) { %w( id title author_name author_email_address parent_id ) }
|
323
|
+
let(:update_columns) { %w(title author_email_address parent_id) }
|
324
|
+
|
325
|
+
context "with column aliases in column list" do
|
326
|
+
let(:columns) { %w( id name author_name author_email_address parent_id ) }
|
327
|
+
should_support_on_duplicate_key_update
|
328
|
+
should_update_fields_mentioned
|
329
|
+
end
|
330
|
+
|
331
|
+
context "with column aliases in update columns list" do
|
332
|
+
let(:update_columns) { %w(name author_email_address parent_id) }
|
333
|
+
should_support_on_duplicate_key_update
|
334
|
+
should_update_fields_mentioned
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
if ENV['AR_VERSION'].to_i >= 6.0
|
339
|
+
context "using ignored columns" do
|
340
|
+
let(:columns) { %w( id title author_name author_email_address parent_id priority ) }
|
341
|
+
let(:values) { [[99, "Book", "John Doe", "john@doe.com", 17, 1]] }
|
342
|
+
let(:update_columns) { %w(name author_email_address parent_id priority) }
|
343
|
+
let(:updated_values) { [[99, "Book - 2nd Edition", "Author Should Not Change", "johndoe@example.com", 57, 2]] }
|
344
|
+
should_support_on_duplicate_key_update
|
345
|
+
should_update_fields_mentioned
|
346
|
+
end
|
347
|
+
end
|
317
348
|
end
|
318
349
|
|
319
350
|
context "with a table that has a non-standard primary key" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
def should_support_recursive_import
|
2
4
|
describe "importing objects with associations" do
|
3
5
|
let(:new_topics) { Build(num_topics, :topic_with_book) }
|
@@ -145,7 +147,7 @@ def should_support_recursive_import
|
|
145
147
|
end
|
146
148
|
|
147
149
|
books.each do |book|
|
148
|
-
|
150
|
+
assert_nil book.topic_id, nil
|
149
151
|
end
|
150
152
|
end
|
151
153
|
|
data/test/synchronize_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'rake'
|
3
5
|
test_dir = Pathname.new File.dirname(__FILE__)
|
@@ -22,7 +24,7 @@ if ActiveSupport::VERSION::STRING < "4.0"
|
|
22
24
|
require 'mocha/test_unit'
|
23
25
|
else
|
24
26
|
require 'active_support/testing/autorun'
|
25
|
-
require "mocha/
|
27
|
+
require "mocha/minitest"
|
26
28
|
end
|
27
29
|
|
28
30
|
require 'timecop'
|
@@ -50,6 +52,12 @@ FileUtils.mkdir_p 'log'
|
|
50
52
|
ActiveRecord::Base.logger = Logger.new("log/test.log")
|
51
53
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
52
54
|
|
55
|
+
if ActiveRecord.respond_to?(:use_yaml_unsafe_load)
|
56
|
+
ActiveRecord.use_yaml_unsafe_load = true
|
57
|
+
elsif ActiveRecord::Base.respond_to?(:use_yaml_unsafe_load)
|
58
|
+
ActiveRecord::Base.use_yaml_unsafe_load = true
|
59
|
+
end
|
60
|
+
|
53
61
|
if ENV['AR_VERSION'].to_f >= 6.0
|
54
62
|
yaml_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.2.1')
|
55
63
|
YAML.safe_load_file(test_dir.join("database.yml"), aliases: true)[adapter]
|
@@ -76,7 +84,7 @@ ActiveSupport::Notifications.subscribe(/active_record.sql/) do |_, _, _, _, hsh|
|
|
76
84
|
end
|
77
85
|
|
78
86
|
require "factory_bot"
|
79
|
-
Dir[File.dirname(__FILE__)
|
87
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |file| require file }
|
80
88
|
|
81
89
|
# Load base/generic schema
|
82
90
|
require test_dir.join("schema/version")
|
@@ -84,7 +92,7 @@ require test_dir.join("schema/generic_schema")
|
|
84
92
|
adapter_schema = test_dir.join("schema/#{adapter}_schema.rb")
|
85
93
|
require adapter_schema if File.exist?(adapter_schema)
|
86
94
|
|
87
|
-
Dir[File.dirname(__FILE__)
|
95
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].sort.each { |file| require file }
|
88
96
|
|
89
97
|
# Prevent this deprecation warning from breaking the tests.
|
90
98
|
Rake::FileList.send(:remove_method, :import)
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- ".rubocop_todo.yml"
|
52
52
|
- Brewfile
|
53
53
|
- CHANGELOG.md
|
54
|
+
- Dockerfile
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE
|
56
57
|
- README.markdown
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- benchmarks/models/test_memory.rb
|
69
70
|
- benchmarks/models/test_myisam.rb
|
70
71
|
- benchmarks/schema/mysql2_schema.rb
|
72
|
+
- docker-compose.yml
|
71
73
|
- gemfiles/4.2.gemfile
|
72
74
|
- gemfiles/5.0.gemfile
|
73
75
|
- gemfiles/5.1.gemfile
|
@@ -75,6 +77,7 @@ files:
|
|
75
77
|
- gemfiles/6.0.gemfile
|
76
78
|
- gemfiles/6.1.gemfile
|
77
79
|
- gemfiles/7.0.gemfile
|
80
|
+
- gemfiles/7.1.gemfile
|
78
81
|
- lib/activerecord-import.rb
|
79
82
|
- lib/activerecord-import/active_record/adapters/abstract_adapter.rb
|
80
83
|
- lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb
|
@@ -138,6 +141,7 @@ files:
|
|
138
141
|
- test/models/question.rb
|
139
142
|
- test/models/rule.rb
|
140
143
|
- test/models/tag.rb
|
144
|
+
- test/models/tag_alias.rb
|
141
145
|
- test/models/topic.rb
|
142
146
|
- test/models/user.rb
|
143
147
|
- test/models/user_token.rb
|
@@ -174,7 +178,7 @@ homepage: https://github.com/zdennis/activerecord-import
|
|
174
178
|
licenses:
|
175
179
|
- MIT
|
176
180
|
metadata: {}
|
177
|
-
post_install_message:
|
181
|
+
post_install_message:
|
178
182
|
rdoc_options: []
|
179
183
|
require_paths:
|
180
184
|
- lib
|
@@ -189,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
193
|
- !ruby/object:Gem::Version
|
190
194
|
version: '0'
|
191
195
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
193
|
-
signing_key:
|
196
|
+
rubygems_version: 3.3.25
|
197
|
+
signing_key:
|
194
198
|
specification_version: 4
|
195
199
|
summary: Bulk insert extension for ActiveRecord
|
196
200
|
test_files:
|
@@ -234,6 +238,7 @@ test_files:
|
|
234
238
|
- test/models/question.rb
|
235
239
|
- test/models/rule.rb
|
236
240
|
- test/models/tag.rb
|
241
|
+
- test/models/tag_alias.rb
|
237
242
|
- test/models/topic.rb
|
238
243
|
- test/models/user.rb
|
239
244
|
- test/models/user_token.rb
|