activerecord-import 0.17.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +40 -23
  4. data/CHANGELOG.md +315 -1
  5. data/Gemfile +23 -13
  6. data/LICENSE +21 -56
  7. data/README.markdown +564 -33
  8. data/Rakefile +2 -1
  9. data/activerecord-import.gemspec +3 -3
  10. data/benchmarks/lib/cli_parser.rb +2 -1
  11. data/benchmarks/schema/{mysql_schema.rb → mysql2_schema.rb} +0 -0
  12. data/gemfiles/5.1.gemfile +2 -0
  13. data/gemfiles/5.2.gemfile +2 -0
  14. data/gemfiles/6.0.gemfile +2 -0
  15. data/gemfiles/6.1.gemfile +1 -0
  16. data/lib/activerecord-import.rb +2 -15
  17. data/lib/activerecord-import/adapters/abstract_adapter.rb +9 -3
  18. data/lib/activerecord-import/adapters/mysql_adapter.rb +17 -11
  19. data/lib/activerecord-import/adapters/postgresql_adapter.rb +68 -20
  20. data/lib/activerecord-import/adapters/sqlite3_adapter.rb +128 -9
  21. data/lib/activerecord-import/base.rb +12 -7
  22. data/lib/activerecord-import/import.rb +514 -166
  23. data/lib/activerecord-import/synchronize.rb +2 -2
  24. data/lib/activerecord-import/value_sets_parser.rb +16 -0
  25. data/lib/activerecord-import/version.rb +1 -1
  26. data/test/adapters/makara_postgis.rb +1 -0
  27. data/test/import_test.rb +274 -23
  28. data/test/makara_postgis/import_test.rb +8 -0
  29. data/test/models/account.rb +3 -0
  30. data/test/models/animal.rb +6 -0
  31. data/test/models/bike_maker.rb +7 -0
  32. data/test/models/tag.rb +1 -1
  33. data/test/models/topic.rb +14 -0
  34. data/test/models/user.rb +3 -0
  35. data/test/models/user_token.rb +4 -0
  36. data/test/schema/generic_schema.rb +30 -8
  37. data/test/schema/mysql2_schema.rb +19 -0
  38. data/test/schema/postgresql_schema.rb +18 -0
  39. data/test/schema/sqlite3_schema.rb +13 -0
  40. data/test/support/factories.rb +9 -8
  41. data/test/support/generate.rb +6 -6
  42. data/test/support/mysql/import_examples.rb +14 -2
  43. data/test/support/postgresql/import_examples.rb +220 -1
  44. data/test/support/shared_examples/on_duplicate_key_ignore.rb +15 -9
  45. data/test/support/shared_examples/on_duplicate_key_update.rb +271 -8
  46. data/test/support/shared_examples/recursive_import.rb +91 -21
  47. data/test/support/sqlite3/import_examples.rb +189 -25
  48. data/test/synchronize_test.rb +8 -0
  49. data/test/test_helper.rb +24 -3
  50. data/test/value_sets_bytes_parser_test.rb +13 -2
  51. metadata +32 -13
  52. data/test/schema/mysql_schema.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5482a79b112f9689eee0261baa906028abd8575f
4
- data.tar.gz: 2f3e76132e6110a5ed17db800f173b5291ddfe8d
2
+ SHA256:
3
+ metadata.gz: 4c61743fafaad0de04ccf2c6bff4439fe66aed03e951e5c42e4f7926cf8dac39
4
+ data.tar.gz: c58d8992957e546b73bb7f7b90eaf2a741f007d2109a16db0e3b3d71b376e1da
5
5
  SHA512:
6
- metadata.gz: 509fe999b0343506f4b1263909d24079394d82d8d3aa16fa5210f35a88b92f40954141949ee7a5f979a81f6105838f0471c5c8cdcfa75a30a5abd38fc96cd1f8
7
- data.tar.gz: 517d7de4678ddf9361647f18d08d95c2256e244ae3e6241413abde6b83992e62f4640279c42abdea8bbc710855800840fd2bf941bdca1b447693f2d82cbaa987
6
+ metadata.gz: 98638b63235eae1c16f27d3be932b8ce4e8f236b24350766792a4fc563d199cb1d048d25efa5d22abf3a21017fa07b9474c3168a4be6c1ba5aaa6e0843d584a3
7
+ data.tar.gz: 5c62bed2684f1b6d60d7e26b8ad13c6b7173a64835eeca9474082122425ab1f340f9063868224eda2539878210887701022e1ff6e6a37593872682bf90768d3a
data/.gitignore CHANGED
@@ -24,6 +24,7 @@ pkg
24
24
  log/*.log
25
25
  test.db
26
26
  test/database.yml
27
+ benchmarks/log/
27
28
 
28
29
  .ruby-*
29
30
  .bundle/
data/.travis.yml CHANGED
@@ -1,33 +1,52 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2.4
4
+ - 2.5.8
5
5
 
6
6
  env:
7
7
  global:
8
8
  # https://github.com/discourse/discourse/blob/master/.travis.yml
9
9
  - RUBY_GC_MALLOC_LIMIT=50000000
10
10
  matrix:
11
- - AR_VERSION=3.2
12
- - AR_VERSION=4.0
13
- - AR_VERSION=4.1
14
- - AR_VERSION=4.2
15
- - AR_VERSION=5.0
11
+ - AR_VERSION=5.1
12
+ - AR_VERSION=5.2
13
+ - AR_VERSION=6.0
14
+ - AR_VERSION=6.1
16
15
 
17
16
  matrix:
18
17
  include:
19
- - rvm: jruby-9.1.7.0
18
+ - rvm: 2.3.8
19
+ env: AR_VERSION=3.2
20
+ - rvm: 2.3.8
21
+ env: AR_VERSION=4.0
22
+ - rvm: 2.3.8
23
+ env: AR_VERSION=4.1
24
+ - rvm: 2.3.8
20
25
  env: AR_VERSION=4.2
21
- before_install:
22
- - gem update --system
23
-
24
- script:
25
- - bundle exec rake test:jdbcsqlite3
26
- - bundle exec rake test:jdbcmysql
27
- - bundle exec rake test:jdbcpostgresql
26
+ - rvm: 2.3.8
27
+ env: AR_VERSION=5.0
28
28
 
29
29
  fast_finish: true
30
30
 
31
+ addons:
32
+ postgresql: "10"
33
+ apt:
34
+ sources:
35
+ - travis-ci/sqlite3
36
+ - mysql-5.7-trusty
37
+ packages:
38
+ - sqlite3
39
+ - mysql-server
40
+ - mysql-client
41
+ - postgresql-10-postgis-2.4
42
+
43
+ before_install:
44
+ - sudo apt-get update
45
+ - gem update --system
46
+ - sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
47
+ - sudo mysql_upgrade
48
+ - sudo service mysql restart
49
+
31
50
  before_script:
32
51
  - mysql -e 'create database activerecord_import_test;'
33
52
  - psql -c 'create database activerecord_import_test;' -U postgres
@@ -36,14 +55,6 @@ before_script:
36
55
  - psql -c 'create extension if not exists "uuid-ossp";' -U postgres
37
56
  - cp test/travis/database.yml test/database.yml
38
57
 
39
- addons:
40
- postgresql: "9.4"
41
- apt:
42
- sources:
43
- - travis-ci/sqlite3
44
- packages:
45
- - sqlite3
46
-
47
58
  script:
48
59
  - bundle exec rake test:mysql2
49
60
  - bundle exec rake test:mysql2_makara
@@ -56,4 +67,10 @@ script:
56
67
  - bundle exec rake test:sqlite3
57
68
  - bundle exec rubocop
58
69
 
59
- sudo: false
70
+ dist: xenial
71
+
72
+ services:
73
+ - mysql
74
+ - postgresql
75
+
76
+ sudo: required
data/CHANGELOG.md CHANGED
@@ -1,10 +1,324 @@
1
+ ## Changes in 1.1.0
2
+
3
+ ### New Features
4
+
5
+ * Add batch progress reporting. Thanks to @gee-forr via \##729.
6
+
7
+ ## Changes in 1.0.8
8
+
9
+ ### Fixes
10
+
11
+ * Use correct method for clearing query cache. Thanks to @EtienneDepaulis via \##719.
12
+
13
+ ## Changes in 1.0.7
14
+
15
+ ### New Features
16
+
17
+ * Use @@max_allowed_packet session variable instead of querying SHOW VARIABLES. Thanks to @diclophis via \#706.
18
+ * Add option :track_validation_failures. 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]. Thanks to @rorymckinley via \#684.
19
+
20
+ ### Fixes
21
+
22
+ * Prevent mass-assignment errors in Rails strict mode. Thanks to @diclophis via \##709.
23
+
24
+ ## Changes in 1.0.6
25
+
26
+ ### Fixes
27
+
28
+ * Handle after_initialize callbacks. Thanks to @AhMohsen46 via \#691 and
29
+ \#692.
30
+ * Fix regression introduced in 1.0.4. Explicity allow adapters to
31
+ support on duplicate key update. Thanks to @dsobiera, @jkowens via \#696.
32
+
33
+ ## Changes in 1.0.5
34
+
35
+ ### Fixes
36
+
37
+ * Allow serialized attributes to be returned from import. Thanks to @timanovsky, @jkowens via \#660.
38
+ * Return ActiveRecord::Connection from
39
+ ActiveREcord::Base#establish_connection. Thanks to @reverentF via
40
+ \#663.
41
+ * Support PostgreSQL array. Thanks to @ujihisa via \#669.
42
+ * Skip loading association ids when column changed. Thanks to @Aristat
43
+ via \#673.
44
+
45
+ ## Changes in 1.0.4
46
+
47
+ ### Fixes
48
+
49
+ * Use prepend pattern for ActiveRecord::Base#establish_connection patching. Thanks to @dombesz via \#648.
50
+ * Fix NoMethodError when using PostgreSQL ENUM types. Thanks to @sebcoetzee via \#651.
51
+ * Fix issue updating optimistic lock in Postgres. Thanks to @timanovsky
52
+ via \#656.
53
+
54
+ ## Changes in 1.0.3
55
+
56
+ ### New Features
57
+
58
+ * Add support for ActiveRecord 6.1.0.alpha. Thanks to @imtayadeway via
59
+ \#642.
60
+
61
+ ### Fixes
62
+
63
+ * Return an empty array for results instead of nil when importing empty
64
+ array. Thanks to @gyfis via \#636.
65
+
66
+ ## Changes in 1.0.2
67
+
68
+ ### New Features
69
+
70
+ * Add support for CockroachDB adapter. Thanks to @willie via \#605.
71
+ * Add support for ActiveRecord 6.0.0.rc1. Thanks to @madeindjs, @bill-filler,
72
+ @jkowens via \#619, \#623.
73
+
74
+ ### Fixes
75
+
76
+ * Fixes NoMethodError when attempting to use nil logger. Thanks to @MattMecel,
77
+ @khiav22357.
78
+ * Fix issue validating STI models. Thanks to @thejbsmith, @jkowens via
79
+ \#626.
80
+
81
+ ## Changes in 1.0.1
82
+
83
+ ### Fixes
84
+
85
+ * Raise an error with a helpful message if array of values exceeds the number of
86
+ columns for a table. Thanks to @golddranks via \#589.
87
+ * Properly check if model responds to import before creating alias.
88
+ Thanks to @jcw- via \#591.
89
+ * No longer pass :returning option to child associations on recursive
90
+ import. Thanks to @dmitriy-kiriyenko via \#595.
91
+ * Fix import issue for models with Postgresql json/jsonb fields. Thanks
92
+ to @stokarenko via \#594.
93
+ * Fix issue importing models with timestamps that contain timezone
94
+ information. Thaks to @dekaikiwi, @jkowens via \#598.
95
+ * Ignore :no_returning when using :recursive option. Thanks to @dgollahon, @jkowens
96
+ via \#599.
97
+
98
+ ## Changes in 1.0.0
99
+
100
+ ### New Features
101
+
102
+ * Move ActiveRecord::Dirty changes to previous_changes after import.
103
+ Thanks to @stokarenko via \#584.
104
+
105
+ ### Breaking Changes
106
+
107
+ * Previously :on_duplicate_key_update was enabled by default for MySQL.
108
+ The update timestamp columns (updated_at, updated_on) would be updated
109
+ on duplicate key. This was behavior is inconsistent with the other database
110
+ adapters and could also be considered surprising. Going forward it must
111
+ be explicitly enabled. See \#548.
112
+
113
+ ## Changes in 0.28.2
114
+
115
+ ### Fixes
116
+
117
+ * Fix issue where validations where not working in certain scenarios.
118
+ Thanks to @CASIXx1 via \#579.
119
+
120
+ ## Changes in 0.28.1
121
+
122
+ ### Fixes
123
+
124
+ * Fix issue where ActiveRecord presence validations were being mutated.
125
+ Limited custom presence validation to bulk imports.
126
+
127
+ ## Changes in 0.28.0
128
+
129
+ ### New Features
130
+
131
+ * Allow updated timestamps to be manually set.Thanks to @Rob117, @jkowens via \#570.
132
+
133
+ ### Fixes
134
+
135
+ * Fix validating presence of belongs_to associations. Existence
136
+ of the parent record is not validated, but the foreign key field
137
+ cannot be empty. Thanks to @Rob117, @jkowens via \#575.
138
+
139
+ ## Changes in 0.27.0
140
+
141
+ ### New Features
142
+
143
+ * Add "secret" option validate_uniqueness to enable uniqueness
144
+ validators when validating import. This is not a recommended
145
+ approach (See #228), but is being added back in for projects
146
+ that depended on this feature. Thanks to @jkowens via \#554.
147
+
148
+ ## Changes in 0.26.0
149
+
150
+ ### New Features
151
+
152
+ * Add on_duplicate_key_update for SQLite. Thanks to @jkowens via \#542.
153
+ * Add option to update all fields on_duplicate_key_update. Thanks to @aimerald, @jkowens via \#543.
154
+
155
+ ### Fixes
156
+
157
+ * Handle deeply frozen options hashes. Thanks to @jturkel via \#546.
158
+ * Switch from FactoryGirl to FactoryBot. Thanks to @koic via \#547.
159
+ * Allow import to work with ProxySQL. Thanks to @GregFarrell via \#550.
160
+
161
+ ## Changes in 0.25.0
162
+
163
+ ### New Features
164
+
165
+ * Add support for makara_postgis adapter. Thanks to @chadwilken via \#527.
166
+ * Skip validating presence of belongs_to associations. Thanks to @Sohair63, @naiyt, @jkowens via \#528.
167
+
168
+ ### Fixes
169
+
170
+ * Add missing require for ActiveSupport.on_load. Thanks to @onk via \#529.
171
+ * Support setting attribute values in before_validation callbacks.
172
+ Thanks to @SirRawlins, @jkowens via \#531.
173
+ * Ignore virtual columns. Thanks to @dbourguignon, @jkowens via \#530.
174
+
175
+ ## Changes in 0.24.0
176
+
177
+ ### Fixes
178
+
179
+ * Use the association primary key when importing. Thanks to @dpogue via \#512.
180
+ * Allow association ids to be updated. Thanks to @Aristat via \#515.
181
+
182
+ ## Changes in 0.23.0
183
+
184
+ ### New Features
185
+
186
+ * Rename `import` method to `bulk_import` and alias to `import`. Thanks
187
+ to @itay-grudev, @jkowens via \#498.
188
+ * Increment lock_version on duplicate key update. Thanks to @aimerald
189
+ via \#500.
190
+
191
+ ### Fixes
192
+
193
+ * Fix import_without_validations_or_callbacks exception if array is empty.
194
+ Thanks to @doloopwhile via \#508.
195
+
196
+ ## Changes in 0.22.0
197
+
198
+ ### New Features
199
+
200
+ * Add support for importing hashes thru a has many association. Thanks
201
+ to @jkowens via \#483.
202
+
203
+ ### Fixes
204
+
205
+ * Fix validation logic for recursive import. For those on Rails 5.0 and 5.1,
206
+ this change requires models with polymorphic associations to specify the `inverse_of`
207
+ argument (See issue #495). Thanks to @eric-simonton-sama, @jkowens via
208
+ \#489.
209
+
210
+ ## Changes in 0.21.0
211
+
212
+ ### New Features
213
+
214
+ * Allow SQL subqueries (objects that respond to .to_sql) to be passed as values. Thanks
215
+ to @jalada, @jkowens via \#471
216
+ * Raise an ArgumentError when importing an array of hashes if any of the
217
+ hash objects have different keys. Thanks to @mbell697 via \#465.
218
+
219
+ ### Fixes
220
+
221
+ * Fix issue loading incorrect foreign key value when syncing belongs_to
222
+ associations with custom foreign key columns. Thanks to @marcgreenstock, @jkowens via \#470.
223
+ * Fix issue importing models with polymorphic belongs_to associations.
224
+ Thanks to @zorab47, @jkowens via \#476.
225
+ * Fix issue importing STI models with ActiveRecord 4.0. Thanks to
226
+ @kazuki-st, @jkowens via \#478.
227
+
228
+ ## Changes in 0.20.2
229
+
230
+ ### Fixes
231
+
232
+ * Unscope model when synchronizing with database. Thanks to @indigoviolet via \#455.
233
+
234
+ ## Changes in 0.20.1
235
+
236
+ ### Fixes
237
+
238
+ * Prevent :on_duplicate_key_update args from being modified. Thanks to @joshuamcginnis, @jkowens via \#451.
239
+
240
+ ## Changes in 0.20.0
241
+
242
+ ### New Features
243
+
244
+ * Allow returning columns to be specified for PostgreSQL. Thanks to
245
+ @tjwp via \#433.
246
+
247
+ ### Fixes
248
+
249
+ * Fixes an issue when bypassing uniqueness validators. Thanks to @vmaxv via \#444.
250
+ * For AR < 4.2, prevent type casting for binary columns on Postgresql. Thanks to @mwalsher via \#446.
251
+ * Fix issue logging class name on import. Thanks to @sophylee, @jkowens via \#447.
252
+ * Copy belongs_to association id to foreign key column before importing. Thanks to @jkowens via \#448.
253
+ * Reset model instance on validate. Thanks to @vmaxv via \#449.
254
+
255
+ ## Changes in 0.19.1
256
+
257
+ ### Fixes
258
+
259
+ * Fix a regression where models weren't properly being marked clean. Thanks to @tjwp via \#434.
260
+ * Raise ActiveRecord::Import::ValueSetTooLargeError when a record being inserted exceeds the
261
+ `max_allowed_packet` for MySQL. Thanks to @saizai, @jkowens via \#437.
262
+ * Fix issue concatenating column names array with primary key. Thanks to @keeguon via \#440.
263
+
264
+ ## Changes in 0.19.0
265
+
266
+ ### New Features
267
+
268
+ * For PostgreSQL, add option to set WHERE condition in conflict_action. Thanks to
269
+ @Saidbek via \#423.
270
+
271
+ ### Fixes
272
+
273
+ * Fix issue importing saved records with serialized fields. Thanks to
274
+ @Andreis13, @jkowens via \#425.
275
+ * Fix issue importing records that have columns defined with default values
276
+ that are functions or expressions. Thanks to @Andreis13, @jkowens via \#428.
277
+
278
+ ## Changes in 0.18.3
279
+
280
+ ### Fixes
281
+
282
+ * Set models new_record attribute to false when importing with
283
+ :on_duplicate_key_ignore. Thanks to @nijikon, @jkowens via \#416.
284
+
285
+ ## Changes in 0.18.2
286
+
287
+ ### Fixes
288
+
289
+ * Enable custom validate callbacks when validating import. Thanks to @afn via \#410.
290
+ * Prevent wrong IDs being set on models when using :on_duplicate_key_ignore.
291
+ Thanks to @afn, @jkowens via \#412.
292
+
293
+ ## Changes in 0.18.1
294
+
295
+ ### Fixes
296
+
297
+ * Fix to enable validation callbacks (before_validation,
298
+ after_validation). Thanks to @sinsoku, @jkowens via \#406.
299
+
300
+ ## Changes in 0.18.0
301
+
302
+ ### New Features
303
+
304
+ * Uniqueness validation is bypassed when validating models since
305
+ it cannot be guaranteed if there are duplicates in a batch.
306
+ Thanks to @jkowens via \#301.
307
+ * Allow for custom timestamp columns. Thanks to @mojidabckuu, @jkowens
308
+ via \#401.
309
+
310
+ ### Fixes
311
+
312
+ * Fix ActiveRecord 5 issue coercing boolean values when serializing
313
+ for the database. Thanks to @rjrobinson, @jkowens via \#403.
314
+
1
315
  ## Changes in 0.17.2
2
316
 
3
317
  ### Fixes
4
318
 
5
319
  * Fix issue where PostgreSQL cannot recognize columns if names
6
320
  include mixed case characters. Thanks to @hugobgranja via \#379.
7
- * Fix an issue for ActiveRecord 5 where serialized fields with
321
+ * Fix an issue for ActiveRecord 5 where serialized fields with
8
322
  default values were not being typecast. Thanks to @whistlerbrk,
9
323
  @jkowens via \#386.
10
324
  * Add option :force_single_insert for MySQL to make sure a single
data/Gemfile CHANGED
@@ -2,32 +2,42 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ version = ENV['AR_VERSION'].to_f
6
+
7
+ mysql2_version = '0.3.0'
8
+ mysql2_version = '0.4.0' if version >= 4.2
9
+ mysql2_version = '0.5.0' if version >= 6.1
10
+ sqlite3_version = '1.3.0'
11
+ sqlite3_version = '1.4.0' if version >= 6.0
12
+ pg_version = '0.9'
13
+ pg_version = '1.1' if version >= 6.1
14
+
5
15
  group :development, :test do
6
- gem 'rubocop', '~> 0.38.0'
16
+ gem 'rubocop', '~> 0.40.0'
7
17
  gem 'rake'
8
18
  end
9
19
 
10
20
  # Database Adapters
11
21
  platforms :ruby do
12
- gem "mysql2", "~> 0.3.0"
13
- gem "pg", "~> 0.9"
14
- gem "sqlite3", "~> 1.3.10"
15
- gem "seamless_database_pool", "~> 1.0.18"
22
+ gem "mysql2", "~> #{mysql2_version}"
23
+ gem "pg", "~> #{pg_version}"
24
+ gem "sqlite3", "~> #{sqlite3_version}"
25
+ gem "seamless_database_pool", "~> 1.0.20"
16
26
  end
17
27
 
18
28
  platforms :jruby do
19
29
  gem "jdbc-mysql"
20
30
  gem "jdbc-postgres"
21
- gem "activerecord-jdbcsqlite3-adapter"
22
- gem "activerecord-jdbcmysql-adapter"
23
- gem "activerecord-jdbcpostgresql-adapter"
31
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3"
32
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3"
33
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3"
24
34
  end
25
35
 
26
36
  # Support libs
27
- gem "factory_girl", "~> 4.2.0"
37
+ gem "factory_bot"
28
38
  gem "timecop"
29
39
  gem "chronic"
30
- gem "mocha"
40
+ gem "mocha", "~> 1.3.0"
31
41
 
32
42
  # Debugging
33
43
  platforms :jruby do
@@ -40,11 +50,11 @@ end
40
50
 
41
51
  platforms :ruby do
42
52
  gem "pry-byebug"
53
+ gem "pry", "~> 0.12.0"
54
+ gem "rb-readline"
43
55
  end
44
56
 
45
- version = ENV['AR_VERSION'] || "4.2"
46
-
47
- if version >= "4.0"
57
+ if version >= 4.0
48
58
  gem "minitest"
49
59
  else
50
60
  gem "test-unit"