activerecord-import 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile +4 -2
- data/README.markdown +8 -7
- data/Rakefile +1 -1
- data/benchmarks/benchmark.rb +2 -1
- data/benchmarks/lib/cli_parser.rb +1 -1
- data/benchmarks/lib/{mysql_benchmark.rb → mysql2_benchmark.rb} +6 -7
- data/gemfiles/3.1.gemfile +0 -2
- data/gemfiles/3.2.gemfile +0 -2
- data/gemfiles/4.0.gemfile +0 -2
- data/gemfiles/4.1.gemfile +0 -2
- data/gemfiles/4.2.gemfile +0 -2
- data/gemfiles/5.0.gemfile +0 -2
- data/lib/activerecord-import/adapters/abstract_adapter.rb +11 -2
- data/lib/activerecord-import/adapters/mysql_adapter.rb +14 -2
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +105 -1
- data/lib/activerecord-import/base.rb +0 -1
- data/lib/activerecord-import/import.rb +92 -21
- data/lib/activerecord-import/version.rb +1 -1
- data/test/database.yml.sample +0 -12
- data/test/import_test.rb +1 -1
- data/test/jdbcmysql/import_test.rb +2 -2
- data/test/jdbcpostgresql/import_test.rb +0 -1
- data/test/models/book.rb +4 -4
- data/test/models/promotion.rb +3 -0
- data/test/models/question.rb +3 -0
- data/test/models/rule.rb +3 -0
- data/test/models/topic.rb +1 -1
- data/test/mysql2/import_test.rb +2 -3
- data/test/mysqlspatial2/import_test.rb +2 -2
- data/test/postgresql/import_test.rb +4 -0
- data/test/schema/generic_schema.rb +19 -2
- data/test/support/{mysql/assertions.rb → assertions.rb} +12 -3
- data/test/support/factories.rb +14 -0
- data/test/support/mysql/import_examples.rb +28 -119
- data/test/support/postgresql/import_examples.rb +156 -1
- data/test/support/shared_examples/on_duplicate_key_update.rb +92 -0
- data/test/test_helper.rb +5 -1
- data/test/travis/build.sh +12 -8
- data/test/travis/database.yml +0 -12
- metadata +14 -23
- data/lib/activerecord-import/active_record/adapters/em_mysql2_adapter.rb +0 -8
- data/lib/activerecord-import/active_record/adapters/mysql_adapter.rb +0 -6
- data/lib/activerecord-import/em_mysql2.rb +0 -7
- data/lib/activerecord-import/mysql.rb +0 -7
- data/test/adapters/em_mysql2.rb +0 -1
- data/test/adapters/mysql.rb +0 -1
- data/test/adapters/mysqlspatial.rb +0 -1
- data/test/em_mysql2/import_test.rb +0 -6
- data/test/mysql/import_test.rb +0 -6
- data/test/mysqlspatial/import_test.rb +0 -6
- data/test/support/em-synchrony_extensions.rb +0 -13
@@ -0,0 +1,92 @@
|
|
1
|
+
def should_support_basic_on_duplicate_key_update
|
2
|
+
describe "#import" do
|
3
|
+
extend ActiveSupport::TestCase::ImportAssertions
|
4
|
+
|
5
|
+
macro(:perform_import){ raise "supply your own #perform_import in a context below" }
|
6
|
+
macro(:updated_topic){ Topic.find(@topic.id) }
|
7
|
+
|
8
|
+
context "with :on_duplicate_key_update and validation checks turned off" do
|
9
|
+
asssertion_group(:should_support_on_duplicate_key_update) do
|
10
|
+
should_not_update_fields_not_mentioned
|
11
|
+
should_update_foreign_keys
|
12
|
+
should_not_update_created_at_on_timestamp_columns
|
13
|
+
should_update_updated_at_on_timestamp_columns
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:columns){ %w( id title author_name author_email_address parent_id ) }
|
17
|
+
let(:values){ [ [ 99, "Book", "John Doe", "john@doe.com", 17 ] ] }
|
18
|
+
let(:updated_values){ [ [ 99, "Book - 2nd Edition", "Author Should Not Change", "johndoe@example.com", 57 ] ] }
|
19
|
+
|
20
|
+
macro(:perform_import) do |*opts|
|
21
|
+
Topic.import columns, updated_values, opts.extract_options!.merge(:on_duplicate_key_update => update_columns , :validate => false)
|
22
|
+
end
|
23
|
+
|
24
|
+
setup do
|
25
|
+
Topic.import columns, values, :validate => false
|
26
|
+
@topic = Topic.find 99
|
27
|
+
end
|
28
|
+
|
29
|
+
context "using an empty array" do
|
30
|
+
let(:update_columns){ [] }
|
31
|
+
should_not_update_fields_not_mentioned
|
32
|
+
should_update_updated_at_on_timestamp_columns
|
33
|
+
end
|
34
|
+
|
35
|
+
context "using string column names" do
|
36
|
+
let(:update_columns){ [ "title", "author_email_address", "parent_id" ] }
|
37
|
+
should_support_on_duplicate_key_update
|
38
|
+
should_update_fields_mentioned
|
39
|
+
end
|
40
|
+
|
41
|
+
context "using symbol column names" do
|
42
|
+
let(:update_columns){ [ :title, :author_email_address, :parent_id ] }
|
43
|
+
should_support_on_duplicate_key_update
|
44
|
+
should_update_fields_mentioned
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with a table that has a non-standard primary key" do
|
49
|
+
let(:columns){ [ :promotion_id, :code ] }
|
50
|
+
let(:values){ [ [ 1, 'DISCOUNT1' ] ] }
|
51
|
+
let(:updated_values){ [ [ 1, 'DISCOUNT2'] ] }
|
52
|
+
let(:update_columns){ [ :code ] }
|
53
|
+
|
54
|
+
macro(:perform_import) do |*opts|
|
55
|
+
Promotion.import columns, updated_values, opts.extract_options!.merge(:on_duplicate_key_update => update_columns, :validate => false)
|
56
|
+
end
|
57
|
+
macro(:updated_promotion){ Promotion.find(@promotion.promotion_id) }
|
58
|
+
|
59
|
+
setup do
|
60
|
+
Promotion.import columns, values, :validate => false
|
61
|
+
@promotion = Promotion.find 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should update specified columns" do
|
65
|
+
perform_import
|
66
|
+
assert_equal 'DISCOUNT2', updated_promotion.code
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with :on_duplicate_key_update turned off" do
|
71
|
+
let(:columns){ %w( id title author_name author_email_address parent_id ) }
|
72
|
+
let(:values){ [ [ 100, "Book", "John Doe", "john@doe.com", 17 ] ] }
|
73
|
+
let(:updated_values){ [ [ 100, "Book - 2nd Edition", "This should raise an exception", "john@nogo.com", 57 ] ] }
|
74
|
+
|
75
|
+
macro(:perform_import) do |*opts|
|
76
|
+
# `:on_duplicate_key_update => false` is the tested feature
|
77
|
+
Topic.import columns, updated_values, opts.extract_options!.merge(:on_duplicate_key_update => false, :validate => false)
|
78
|
+
end
|
79
|
+
|
80
|
+
setup do
|
81
|
+
Topic.import columns, values, :validate => false
|
82
|
+
@topic = Topic.find 100
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should raise ActiveRecord::RecordNotUnique" do
|
86
|
+
assert_raise ActiveRecord::RecordNotUnique do
|
87
|
+
perform_import
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ ENV["RAILS_ENV"] = "test"
|
|
10
10
|
require "bundler"
|
11
11
|
Bundler.setup
|
12
12
|
|
13
|
-
require 'pry'
|
13
|
+
require 'pry' unless RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /jruby/
|
14
14
|
|
15
15
|
require "active_record"
|
16
16
|
require "active_record/fixtures"
|
@@ -55,3 +55,7 @@ Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }
|
|
55
55
|
|
56
56
|
# Prevent this deprecation warning from breaking the tests.
|
57
57
|
Rake::FileList.send(:remove_method, :import)
|
58
|
+
|
59
|
+
if ENV['AR_VERSION'].to_f >= 4.2
|
60
|
+
ActiveSupport::TestCase.test_order = :sorted
|
61
|
+
end
|
data/test/travis/build.sh
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
#!/bin/bash
|
2
|
-
set -e
|
3
|
-
set +x
|
2
|
+
# set -e
|
3
|
+
# set +x
|
4
4
|
|
5
5
|
function run {
|
6
|
-
|
7
|
-
|
6
|
+
statement=$@
|
7
|
+
logfile=$4.log
|
8
|
+
$statement &> $logfile
|
9
|
+
if [ $? != 0 ] ; then
|
10
|
+
printf "AR_VERSION=$AR_VERSION $statement \e[31mFAILED\e[0m\n"
|
11
|
+
cat $logfile
|
12
|
+
else
|
13
|
+
printf "AR_VERSION=$AR_VERSION $statement \e[32mPASSED\e[0m\n"
|
14
|
+
fi
|
8
15
|
}
|
9
16
|
|
10
17
|
for activerecord_version in "3.1" "3.2" "4.0" "4.1" "4.2" "5.0" ; do
|
11
18
|
export AR_VERSION=$activerecord_version
|
12
19
|
|
13
|
-
bundle update activerecord
|
20
|
+
bundle update activerecord > /dev/null
|
14
21
|
|
15
|
-
run bundle exec rake test:em_mysql2 # Run tests for em_mysql2
|
16
|
-
run bundle exec rake test:mysql # Run tests for mysql
|
17
22
|
run bundle exec rake test:mysql2 # Run tests for mysql2
|
18
23
|
run bundle exec rake test:mysql2spatial # Run tests for mysql2spatial
|
19
|
-
run bundle exec rake test:mysqlspatial # Run tests for mysqlspatial
|
20
24
|
run bundle exec rake test:postgis # Run tests for postgis
|
21
25
|
run bundle exec rake test:postgresql # Run tests for postgresql
|
22
26
|
run bundle exec rake test:seamless_database_pool # Run tests for seamless_database_pool
|
data/test/travis/database.yml
CHANGED
@@ -5,25 +5,13 @@ common: &common
|
|
5
5
|
host: localhost
|
6
6
|
database: activerecord_import_test
|
7
7
|
|
8
|
-
mysql: &mysql
|
9
|
-
<<: *common
|
10
|
-
adapter: mysql
|
11
|
-
|
12
8
|
mysql2: &mysql2
|
13
9
|
<<: *common
|
14
10
|
adapter: mysql2
|
15
11
|
|
16
|
-
mysqlspatial:
|
17
|
-
<<: *mysql
|
18
|
-
|
19
12
|
mysql2spatial:
|
20
13
|
<<: *mysql2
|
21
14
|
|
22
|
-
em_mysql2:
|
23
|
-
<<: *common
|
24
|
-
adapter: em_mysql2
|
25
|
-
pool: 5
|
26
|
-
|
27
15
|
seamless_database_pool:
|
28
16
|
<<: *common
|
29
17
|
adapter: seamless_database_pool
|
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: 0.
|
4
|
+
version: 0.12.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: 2016-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- ".gitignore"
|
50
50
|
- ".travis.yml"
|
51
51
|
- Brewfile
|
52
|
+
- CHANGELOG.md
|
52
53
|
- Gemfile
|
53
54
|
- LICENSE
|
54
55
|
- README.markdown
|
@@ -59,7 +60,7 @@ files:
|
|
59
60
|
- benchmarks/lib/base.rb
|
60
61
|
- benchmarks/lib/cli_parser.rb
|
61
62
|
- benchmarks/lib/float.rb
|
62
|
-
- benchmarks/lib/
|
63
|
+
- benchmarks/lib/mysql2_benchmark.rb
|
63
64
|
- benchmarks/lib/output_to_csv.rb
|
64
65
|
- benchmarks/lib/output_to_html.rb
|
65
66
|
- benchmarks/models/test_innodb.rb
|
@@ -74,11 +75,9 @@ files:
|
|
74
75
|
- gemfiles/5.0.gemfile
|
75
76
|
- lib/activerecord-import.rb
|
76
77
|
- lib/activerecord-import/active_record/adapters/abstract_adapter.rb
|
77
|
-
- lib/activerecord-import/active_record/adapters/em_mysql2_adapter.rb
|
78
78
|
- lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb
|
79
79
|
- lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb
|
80
80
|
- lib/activerecord-import/active_record/adapters/mysql2_adapter.rb
|
81
|
-
- lib/activerecord-import/active_record/adapters/mysql_adapter.rb
|
82
81
|
- lib/activerecord-import/active_record/adapters/postgresql_adapter.rb
|
83
82
|
- lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb
|
84
83
|
- lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb
|
@@ -89,29 +88,23 @@ files:
|
|
89
88
|
- lib/activerecord-import/adapters/postgresql_adapter.rb
|
90
89
|
- lib/activerecord-import/adapters/sqlite3_adapter.rb
|
91
90
|
- lib/activerecord-import/base.rb
|
92
|
-
- lib/activerecord-import/em_mysql2.rb
|
93
91
|
- lib/activerecord-import/import.rb
|
94
|
-
- lib/activerecord-import/mysql.rb
|
95
92
|
- lib/activerecord-import/mysql2.rb
|
96
93
|
- lib/activerecord-import/postgresql.rb
|
97
94
|
- lib/activerecord-import/sqlite3.rb
|
98
95
|
- lib/activerecord-import/synchronize.rb
|
99
96
|
- lib/activerecord-import/value_sets_parser.rb
|
100
97
|
- lib/activerecord-import/version.rb
|
101
|
-
- test/adapters/em_mysql2.rb
|
102
98
|
- test/adapters/jdbcmysql.rb
|
103
99
|
- test/adapters/jdbcpostgresql.rb
|
104
|
-
- test/adapters/mysql.rb
|
105
100
|
- test/adapters/mysql2.rb
|
106
101
|
- test/adapters/mysql2spatial.rb
|
107
|
-
- test/adapters/mysqlspatial.rb
|
108
102
|
- test/adapters/postgis.rb
|
109
103
|
- test/adapters/postgresql.rb
|
110
104
|
- test/adapters/seamless_database_pool.rb
|
111
105
|
- test/adapters/spatialite.rb
|
112
106
|
- test/adapters/sqlite3.rb
|
113
107
|
- test/database.yml.sample
|
114
|
-
- test/em_mysql2/import_test.rb
|
115
108
|
- test/import_test.rb
|
116
109
|
- test/jdbcmysql/import_test.rb
|
117
110
|
- test/jdbcpostgresql/import_test.rb
|
@@ -119,11 +112,12 @@ files:
|
|
119
112
|
- test/models/chapter.rb
|
120
113
|
- test/models/end_note.rb
|
121
114
|
- test/models/group.rb
|
115
|
+
- test/models/promotion.rb
|
116
|
+
- test/models/question.rb
|
117
|
+
- test/models/rule.rb
|
122
118
|
- test/models/topic.rb
|
123
119
|
- test/models/widget.rb
|
124
|
-
- test/mysql/import_test.rb
|
125
120
|
- test/mysql2/import_test.rb
|
126
|
-
- test/mysqlspatial/import_test.rb
|
127
121
|
- test/mysqlspatial2/import_test.rb
|
128
122
|
- test/postgis/import_test.rb
|
129
123
|
- test/postgresql/import_test.rb
|
@@ -132,12 +126,12 @@ files:
|
|
132
126
|
- test/schema/version.rb
|
133
127
|
- test/sqlite3/import_test.rb
|
134
128
|
- test/support/active_support/test_case_extensions.rb
|
135
|
-
- test/support/
|
129
|
+
- test/support/assertions.rb
|
136
130
|
- test/support/factories.rb
|
137
131
|
- test/support/generate.rb
|
138
|
-
- test/support/mysql/assertions.rb
|
139
132
|
- test/support/mysql/import_examples.rb
|
140
133
|
- test/support/postgresql/import_examples.rb
|
134
|
+
- test/support/shared_examples/on_duplicate_key_update.rb
|
141
135
|
- test/synchronize_test.rb
|
142
136
|
- test/test_helper.rb
|
143
137
|
- test/travis/build.sh
|
@@ -169,20 +163,16 @@ signing_key:
|
|
169
163
|
specification_version: 4
|
170
164
|
summary: Bulk-loading extension for ActiveRecord
|
171
165
|
test_files:
|
172
|
-
- test/adapters/em_mysql2.rb
|
173
166
|
- test/adapters/jdbcmysql.rb
|
174
167
|
- test/adapters/jdbcpostgresql.rb
|
175
|
-
- test/adapters/mysql.rb
|
176
168
|
- test/adapters/mysql2.rb
|
177
169
|
- test/adapters/mysql2spatial.rb
|
178
|
-
- test/adapters/mysqlspatial.rb
|
179
170
|
- test/adapters/postgis.rb
|
180
171
|
- test/adapters/postgresql.rb
|
181
172
|
- test/adapters/seamless_database_pool.rb
|
182
173
|
- test/adapters/spatialite.rb
|
183
174
|
- test/adapters/sqlite3.rb
|
184
175
|
- test/database.yml.sample
|
185
|
-
- test/em_mysql2/import_test.rb
|
186
176
|
- test/import_test.rb
|
187
177
|
- test/jdbcmysql/import_test.rb
|
188
178
|
- test/jdbcpostgresql/import_test.rb
|
@@ -190,11 +180,12 @@ test_files:
|
|
190
180
|
- test/models/chapter.rb
|
191
181
|
- test/models/end_note.rb
|
192
182
|
- test/models/group.rb
|
183
|
+
- test/models/promotion.rb
|
184
|
+
- test/models/question.rb
|
185
|
+
- test/models/rule.rb
|
193
186
|
- test/models/topic.rb
|
194
187
|
- test/models/widget.rb
|
195
|
-
- test/mysql/import_test.rb
|
196
188
|
- test/mysql2/import_test.rb
|
197
|
-
- test/mysqlspatial/import_test.rb
|
198
189
|
- test/mysqlspatial2/import_test.rb
|
199
190
|
- test/postgis/import_test.rb
|
200
191
|
- test/postgresql/import_test.rb
|
@@ -203,12 +194,12 @@ test_files:
|
|
203
194
|
- test/schema/version.rb
|
204
195
|
- test/sqlite3/import_test.rb
|
205
196
|
- test/support/active_support/test_case_extensions.rb
|
206
|
-
- test/support/
|
197
|
+
- test/support/assertions.rb
|
207
198
|
- test/support/factories.rb
|
208
199
|
- test/support/generate.rb
|
209
|
-
- test/support/mysql/assertions.rb
|
210
200
|
- test/support/mysql/import_examples.rb
|
211
201
|
- test/support/postgresql/import_examples.rb
|
202
|
+
- test/support/shared_examples/on_duplicate_key_update.rb
|
212
203
|
- test/synchronize_test.rb
|
213
204
|
- test/test_helper.rb
|
214
205
|
- test/travis/build.sh
|
@@ -1,7 +0,0 @@
|
|
1
|
-
warn <<-MSG
|
2
|
-
[DEPRECATION] loading activerecord-import via 'require "activerecord-import/<adapter-name>"'
|
3
|
-
is deprecated. Update to autorequire using 'require "activerecord-import"'. See
|
4
|
-
http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
|
5
|
-
MSG
|
6
|
-
|
7
|
-
require "activerecord-import"
|
@@ -1,7 +0,0 @@
|
|
1
|
-
warn <<-MSG
|
2
|
-
[DEPRECATION] loading activerecord-import via 'require "activerecord-import/<adapter-name>"'
|
3
|
-
is deprecated. Update to autorequire using 'require "activerecord-import"'. See
|
4
|
-
http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
|
5
|
-
MSG
|
6
|
-
|
7
|
-
require "activerecord-import"
|
data/test/adapters/em_mysql2.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ENV["ARE_DB"] = "em_mysql2"
|
data/test/adapters/mysql.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ENV["ARE_DB"] = "mysql"
|
@@ -1 +0,0 @@
|
|
1
|
-
ENV["ARE_DB"] = "mysqlspatial"
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
|
5
|
-
|
6
|
-
should_support_mysql_import_functionality
|
data/test/mysql/import_test.rb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
|
5
|
-
|
6
|
-
should_support_mysql_import_functionality
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
|
5
|
-
|
6
|
-
should_support_mysql_import_functionality
|
@@ -1,13 +0,0 @@
|
|
1
|
-
if defined?(EM::Synchrony) && ActiveRecord::VERSION::STRING >= "4.0"
|
2
|
-
module EM::Synchrony
|
3
|
-
module ActiveRecord
|
4
|
-
module Adapter
|
5
|
-
def reset_transaction
|
6
|
-
@transaction_manager = ::ActiveRecord::ConnectionAdapters::TransactionManager.new(self)
|
7
|
-
end
|
8
|
-
|
9
|
-
delegate :open_transactions, :current_transaction, :begin_transaction, :commit_transaction, :rollback_transaction, to: :transaction_manager
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|