activerecord-import 1.0.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yaml +113 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +74 -8
  5. data/.rubocop_todo.yml +6 -16
  6. data/Brewfile +3 -1
  7. data/CHANGELOG.md +115 -3
  8. data/Gemfile +12 -10
  9. data/LICENSE +21 -56
  10. data/README.markdown +71 -60
  11. data/Rakefile +2 -0
  12. data/activerecord-import.gemspec +6 -5
  13. data/benchmarks/benchmark.rb +10 -4
  14. data/benchmarks/lib/base.rb +4 -2
  15. data/benchmarks/lib/cli_parser.rb +4 -2
  16. data/benchmarks/lib/float.rb +2 -0
  17. data/benchmarks/lib/mysql2_benchmark.rb +2 -0
  18. data/benchmarks/lib/output_to_csv.rb +2 -0
  19. data/benchmarks/lib/output_to_html.rb +4 -2
  20. data/benchmarks/models/test_innodb.rb +2 -0
  21. data/benchmarks/models/test_memory.rb +2 -0
  22. data/benchmarks/models/test_myisam.rb +2 -0
  23. data/benchmarks/schema/{mysql_schema.rb → mysql2_schema.rb} +2 -0
  24. data/gemfiles/4.2.gemfile +2 -0
  25. data/gemfiles/5.0.gemfile +2 -0
  26. data/gemfiles/5.1.gemfile +2 -0
  27. data/gemfiles/5.2.gemfile +2 -0
  28. data/gemfiles/6.0.gemfile +4 -1
  29. data/gemfiles/6.1.gemfile +4 -1
  30. data/gemfiles/7.0.gemfile +4 -0
  31. data/lib/activerecord-import/active_record/adapters/abstract_adapter.rb +2 -0
  32. data/lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb +6 -4
  33. data/lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb +2 -0
  34. data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +2 -0
  35. data/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +2 -0
  36. data/lib/activerecord-import/active_record/adapters/postgresql_adapter.rb +2 -0
  37. data/lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb +2 -0
  38. data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +2 -0
  39. data/lib/activerecord-import/adapters/abstract_adapter.rb +14 -5
  40. data/lib/activerecord-import/adapters/em_mysql2_adapter.rb +2 -0
  41. data/lib/activerecord-import/adapters/mysql2_adapter.rb +2 -0
  42. data/lib/activerecord-import/adapters/mysql_adapter.rb +33 -25
  43. data/lib/activerecord-import/adapters/postgresql_adapter.rb +69 -56
  44. data/lib/activerecord-import/adapters/sqlite3_adapter.rb +39 -39
  45. data/lib/activerecord-import/base.rb +10 -2
  46. data/lib/activerecord-import/import.rb +143 -62
  47. data/lib/activerecord-import/mysql2.rb +2 -0
  48. data/lib/activerecord-import/postgresql.rb +2 -0
  49. data/lib/activerecord-import/sqlite3.rb +2 -0
  50. data/lib/activerecord-import/synchronize.rb +3 -1
  51. data/lib/activerecord-import/value_sets_parser.rb +5 -0
  52. data/lib/activerecord-import/version.rb +3 -1
  53. data/lib/activerecord-import.rb +3 -1
  54. data/test/adapters/jdbcmysql.rb +2 -0
  55. data/test/adapters/jdbcpostgresql.rb +2 -0
  56. data/test/adapters/jdbcsqlite3.rb +2 -0
  57. data/test/adapters/makara_postgis.rb +2 -0
  58. data/test/adapters/mysql2.rb +2 -0
  59. data/test/adapters/mysql2_makara.rb +2 -0
  60. data/test/adapters/mysql2spatial.rb +2 -0
  61. data/test/adapters/postgis.rb +2 -0
  62. data/test/adapters/postgresql.rb +2 -0
  63. data/test/adapters/postgresql_makara.rb +2 -0
  64. data/test/adapters/seamless_database_pool.rb +2 -0
  65. data/test/adapters/spatialite.rb +2 -0
  66. data/test/adapters/sqlite3.rb +2 -0
  67. data/test/{travis → github}/database.yml +3 -1
  68. data/test/import_test.rb +93 -2
  69. data/test/jdbcmysql/import_test.rb +5 -3
  70. data/test/jdbcpostgresql/import_test.rb +4 -2
  71. data/test/jdbcsqlite3/import_test.rb +4 -2
  72. data/test/makara_postgis/import_test.rb +4 -2
  73. data/test/models/account.rb +2 -0
  74. data/test/models/alarm.rb +2 -0
  75. data/test/models/animal.rb +8 -0
  76. data/test/models/bike_maker.rb +3 -0
  77. data/test/models/book.rb +2 -0
  78. data/test/models/car.rb +2 -0
  79. data/test/models/card.rb +5 -0
  80. data/test/models/chapter.rb +2 -0
  81. data/test/models/customer.rb +8 -0
  82. data/test/models/deck.rb +8 -0
  83. data/test/models/dictionary.rb +2 -0
  84. data/test/models/discount.rb +2 -0
  85. data/test/models/end_note.rb +2 -0
  86. data/test/models/group.rb +2 -0
  87. data/test/models/order.rb +8 -0
  88. data/test/models/playing_card.rb +4 -0
  89. data/test/models/promotion.rb +2 -0
  90. data/test/models/question.rb +2 -0
  91. data/test/models/rule.rb +2 -0
  92. data/test/models/tag.rb +3 -0
  93. data/test/models/tag_alias.rb +5 -0
  94. data/test/models/topic.rb +7 -0
  95. data/test/models/user.rb +2 -0
  96. data/test/models/user_token.rb +2 -0
  97. data/test/models/vendor.rb +2 -0
  98. data/test/models/widget.rb +2 -0
  99. data/test/mysql2/import_test.rb +5 -3
  100. data/test/mysql2_makara/import_test.rb +5 -3
  101. data/test/mysqlspatial2/import_test.rb +5 -3
  102. data/test/postgis/import_test.rb +4 -2
  103. data/test/postgresql/import_test.rb +4 -2
  104. data/test/schema/generic_schema.rb +34 -0
  105. data/test/schema/jdbcpostgresql_schema.rb +3 -1
  106. data/test/schema/mysql2_schema.rb +2 -0
  107. data/test/schema/postgis_schema.rb +3 -1
  108. data/test/schema/postgresql_schema.rb +16 -0
  109. data/test/schema/sqlite3_schema.rb +2 -0
  110. data/test/schema/version.rb +2 -0
  111. data/test/sqlite3/import_test.rb +4 -2
  112. data/test/support/active_support/test_case_extensions.rb +2 -0
  113. data/test/support/assertions.rb +2 -0
  114. data/test/support/factories.rb +2 -0
  115. data/test/support/generate.rb +4 -2
  116. data/test/support/mysql/import_examples.rb +2 -1
  117. data/test/support/postgresql/import_examples.rb +96 -2
  118. data/test/support/shared_examples/on_duplicate_key_ignore.rb +2 -0
  119. data/test/support/shared_examples/on_duplicate_key_update.rb +50 -9
  120. data/test/support/shared_examples/recursive_import.rb +32 -1
  121. data/test/support/sqlite3/import_examples.rb +2 -1
  122. data/test/synchronize_test.rb +2 -0
  123. data/test/test_helper.rb +30 -5
  124. data/test/value_sets_bytes_parser_test.rb +3 -1
  125. data/test/value_sets_records_parser_test.rb +3 -1
  126. metadata +27 -16
  127. data/.travis.yml +0 -70
  128. data/gemfiles/3.2.gemfile +0 -2
  129. data/gemfiles/4.0.gemfile +0 -2
  130. data/gemfiles/4.1.gemfile +0 -2
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
- # activerecord-import [![Build Status](https://travis-ci.org/zdennis/activerecord-import.svg?branch=master)](https://travis-ci.org/zdennis/activerecord-import)
1
+ # Activerecord-Import ![Build Status](https://github.com/zdennis/activerecord-import/actions/workflows/test.yaml/badge.svg)
2
2
 
3
- activerecord-import is a library for bulk inserting data using ActiveRecord.
3
+ Activerecord-Import is a library for bulk inserting data using ActiveRecord.
4
4
 
5
5
  One of its major features is following activerecord associations and generating the minimal
6
6
  number of SQL insert statements required, avoiding the N+1 insert problem. An example probably
@@ -23,10 +23,10 @@ an 18 hour batch process to <2 hrs.
23
23
 
24
24
  The gem provides the following high-level features:
25
25
 
26
- * activerecord-import can work with raw columns and arrays of values (fastest)
27
- * activerecord-import works with model objects (faster)
28
- * activerecord-import can perform validations (fast)
29
- * activerecord-import can perform on duplicate key updates (requires MySQL or Postgres 9.5+)
26
+ * Works with raw columns and arrays of values (fastest)
27
+ * Works with model objects (faster)
28
+ * Performs validations (fast)
29
+ * Performs on duplicate key updates (requires MySQL, SQLite 3.24.0+, or Postgres 9.5+)
30
30
 
31
31
  ## Table of Contents
32
32
 
@@ -54,11 +54,14 @@ The gem provides the following high-level features:
54
54
  * [More Information](#more-information)
55
55
  * [Contributing](#contributing)
56
56
  * [Running Tests](#running-tests)
57
+ * [Issue Triage](#issue-triage)
57
58
 
58
59
  ### Examples
59
60
 
60
61
  #### Introduction
61
62
 
63
+ This gem adds an `import` method (or `bulk_import`, for compatibility with gems like `elasticsearch-model`; see [Conflicts With Other Gems](#conflicts-with-other-gems)) to ActiveRecord classes.
64
+
62
65
  Without `activerecord-import`, you'd write something like this:
63
66
 
64
67
  ```ruby
@@ -85,7 +88,7 @@ The `import` method can take an array of column names (string or symbols) and an
85
88
 
86
89
  ```ruby
87
90
  columns = [ :title, :author ]
88
- values = [ ['Book1', 'FooManChu'], ['Book2', 'Bob Jones'] ]
91
+ values = [ ['Book1', 'George Orwell'], ['Book2', 'Bob Jones'] ]
89
92
 
90
93
  # Importing without model validations
91
94
  Book.import columns, values, validate: false
@@ -102,7 +105,7 @@ Book.import columns, values
102
105
  The `import` method can take an array of hashes. The keys map to the column names in the database.
103
106
 
104
107
  ```ruby
105
- values = [{ title: 'Book1', author: 'FooManChu' }, { title: 'Book2', author: 'Bob Jones'}]
108
+ values = [{ title: 'Book1', author: 'George Orwell' }, { title: 'Book2', author: 'Bob Jones'}]
106
109
 
107
110
  # Importing without model validations
108
111
  Book.import values, validate: false
@@ -119,7 +122,7 @@ The `import` method can take an array of column names and an array of hash objec
119
122
 
120
123
  ```ruby
121
124
  books = [
122
- { title: "Book 1", author: "FooManChu" },
125
+ { title: "Book 1", author: "George Orwell" },
123
126
  { title: "Book 2", author: "Bob Jones" }
124
127
  ]
125
128
  columns = [ :title ]
@@ -171,7 +174,7 @@ The `import` method can take an array of models. The attributes will be pulled o
171
174
 
172
175
  ```ruby
173
176
  books = [
174
- Book.new(title: "Book 1", author: "FooManChu"),
177
+ Book.new(title: "Book 1", author: "George Orwell"),
175
178
  Book.new(title: "Book 2", author: "Bob Jones")
176
179
  ]
177
180
 
@@ -189,7 +192,7 @@ The `import` method can take an array of column names and an array of models. Th
189
192
 
190
193
  ```ruby
191
194
  books = [
192
- Book.new(title: "Book 1", author: "FooManChu"),
195
+ Book.new(title: "Book 1", author: "George Orwell"),
193
196
  Book.new(title: "Book 2", author: "Bob Jones")
194
197
  ]
195
198
  columns = [ :title ]
@@ -217,7 +220,7 @@ The `import` method can take a `batch_size` option to control the number of rows
217
220
 
218
221
  ```ruby
219
222
  books = [
220
- Book.new(title: "Book 1", author: "FooManChu"),
223
+ Book.new(title: "Book 1", author: "George Orwell"),
221
224
  Book.new(title: "Book 2", author: "Bob Jones"),
222
225
  Book.new(title: "Book 1", author: "John Doe"),
223
226
  Book.new(title: "Book 2", author: "Richard Wright")
@@ -228,9 +231,22 @@ columns = [ :title ]
228
231
  Book.import columns, books, batch_size: 2
229
232
  ```
230
233
 
234
+ If your import is particularly large or slow (possibly due to [callbacks](#callbacks)) whilst batch importing, you might want a way to report back on progress. This is supported by passing a callable as the `batch_progress` option. e.g:
235
+
236
+ ```ruby
237
+ my_proc = ->(rows_size, num_batches, current_batch_number, batch_duration_in_secs) {
238
+ # Using the arguments provided to the callable, you can
239
+ # send an email, post to a websocket,
240
+ # update slack, alert if import is taking too long, etc.
241
+ }
242
+
243
+ Book.import columns, books, batch_size: 2, batch_progress: my_proc
244
+ ```
245
+
231
246
  #### Recursive
232
247
 
233
- NOTE: This only works with PostgreSQL.
248
+ > **Note**
249
+ > This only works with PostgreSQL and ActiveRecord objects. This won't work with hashes or arrays as recursive inputs.
234
250
 
235
251
  Assume that Books <code>has_many</code> Reviews.
236
252
 
@@ -246,19 +262,21 @@ Book.import books, recursive: true
246
262
 
247
263
  ### Options
248
264
 
249
- Key | Options | Default | Description
250
- ----------------------- | --------------------- | ------------------ | -----------
251
- :validate | `true`/`false` | `true` | Whether or not to run `ActiveRecord` validations (uniqueness skipped). This option will always be true when using `import!`.
252
- :validate_uniqueness | `true`/`false` | `false` | Whether or not to run uniqueness validations, has potential pitfalls, use with caution (requires `>= v0.27.0`).
253
- :on_duplicate_key_ignore| `true`/`false` | `false` | Allows skipping records with duplicate keys. See [here](https://github.com/zdennis/activerecord-import/#duplicate-key-ignore) for more details.
254
- :ignore | `true`/`false` | `false` | Alias for :on_duplicate_key_ignore.
255
- :on_duplicate_key_update| :all, `Array`, `Hash` | N/A | Allows upsert logic to be used. See [here](https://github.com/zdennis/activerecord-import/#duplicate-key-update) for more details.
256
- :synchronize | `Array` | N/A | An array of ActiveRecord instances. This synchronizes existing instances in memory with updates from the import.
257
- :timestamps | `true`/`false` | `true` | Enables/disables timestamps on imported records.
258
- :recursive | `true`/`false` | `false` | Imports has_many/has_one associations (PostgreSQL only).
259
- :batch_size | `Integer` | total # of records | Max number of records to insert per import
260
- :raise_error | `true`/`false` | `false` | Throws an exception if there are invalid records. `import!` is a shortcut for this.
261
-
265
+ Key | Options | Default | Description
266
+ ------------------------- | --------------------- | ------------------ | -----------
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, has potential pitfalls, use with caution (requires `>= v0.27.0`).
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
+ :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
+ :on_duplicate_key_ignore | `true`/`false` | `false` | Allows skipping records with duplicate keys. See [here](#duplicate-key-ignore) for more details.
272
+ :ignore | `true`/`false` | `false` | Alias for :on_duplicate_key_ignore.
273
+ :on_duplicate_key_update | :all, `Array`, `Hash` | N/A | Allows upsert logic to be used. See [here](#duplicate-key-update) for more details.
274
+ :synchronize | `Array` | N/A | An array of ActiveRecord instances. This synchronizes existing instances in memory with updates from the import.
275
+ :timestamps | `true`/`false` | `true` | Enables/disables timestamps on imported records.
276
+ :recursive | `true`/`false` | `false` | Imports has_many/has_one associations (PostgreSQL only).
277
+ :batch_size | `Integer` | total # of records | Max number of records to insert per import
278
+ :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
+ :all_or_none | `true`/`false` | `false` | Will not import any records if there is a record with validation errors.
262
280
 
263
281
  #### Duplicate Key Ignore
264
282
 
@@ -267,14 +285,14 @@ Key | Options | Default | Descripti
267
285
  For Postgres 9.5+ it adds `ON CONFLICT DO NOTHING`, for MySQL it uses `INSERT IGNORE`, and for SQLite it uses `INSERT OR IGNORE`. Cannot be enabled on a recursive import. For database adapters that normally support setting primary keys on imported objects, this option prevents that from occurring.
268
286
 
269
287
  ```ruby
270
- book = Book.create! title: "Book1", author: "FooManChu"
288
+ book = Book.create! title: "Book1", author: "George Orwell"
271
289
  book.title = "Updated Book Title"
272
290
  book.author = "Bob Barker"
273
291
 
274
292
  Book.import [book], on_duplicate_key_ignore: true
275
293
 
276
294
  book.reload.title # => "Book1" (stayed the same)
277
- book.reload.author # => "FooManChu" (stayed the same)
295
+ book.reload.author # => "George Orwell" (stayed the same)
278
296
  ```
279
297
 
280
298
  The option `:on_duplicate_key_ignore` is bypassed when `:recursive` is enabled for [PostgreSQL imports](https://github.com/zdennis/activerecord-import/wiki#recursive-example-postgresql-only).
@@ -290,7 +308,7 @@ This will use MySQL's `ON DUPLICATE KEY UPDATE` or Postgres/SQLite `ON CONFLICT
290
308
  Basic Update
291
309
 
292
310
  ```ruby
293
- book = Book.create! title: "Book1", author: "FooManChu"
311
+ book = Book.create! title: "Book1", author: "George Orwell"
294
312
  book.title = "Updated Book Title"
295
313
  book.author = "Bob Barker"
296
314
 
@@ -304,13 +322,13 @@ Book.import [book], on_duplicate_key_update: {conflict_target: [:id], columns: [
304
322
  Book.import [book], on_duplicate_key_update: [:title]
305
323
 
306
324
  book.reload.title # => "Updated Book Title" (changed)
307
- book.reload.author # => "FooManChu" (stayed the same)
325
+ book.reload.author # => "George Orwell" (stayed the same)
308
326
  ```
309
327
 
310
328
  Using the value from another column
311
329
 
312
330
  ```ruby
313
- book = Book.create! title: "Book1", author: "FooManChu"
331
+ book = Book.create! title: "Book1", author: "George Orwell"
314
332
  book.title = "Updated Book Title"
315
333
 
316
334
  # MySQL version
@@ -328,7 +346,7 @@ book.reload.author # => "Updated Book Title" (changed)
328
346
  Using Custom SQL
329
347
 
330
348
  ```ruby
331
- book = Book.create! title: "Book1", author: "FooManChu"
349
+ book = Book.create! title: "Book1", author: "George Orwell"
332
350
  book.author = "Bob Barker"
333
351
 
334
352
  # MySQL version
@@ -349,7 +367,7 @@ book.reload.author # => "Bob Barker" (changed)
349
367
  PostgreSQL Using constraints
350
368
 
351
369
  ```ruby
352
- book = Book.create! title: "Book1", author: "FooManChu", edition: 3, published_at: nil
370
+ book = Book.create! title: "Book1", author: "George Orwell", edition: 3, published_at: nil
353
371
  book.published_at = Time.now
354
372
 
355
373
  # in migration
@@ -363,7 +381,7 @@ Book.import [book], on_duplicate_key_update: {constraint_name: :for_upsert, colu
363
381
 
364
382
 
365
383
  book.reload.title # => "Book1" (stayed the same)
366
- book.reload.author # => "FooManChu" (stayed the same)
384
+ book.reload.author # => "George Orwell" (stayed the same)
367
385
  book.reload.edition # => 3 (stayed the same)
368
386
  book.reload.published_at # => 2017-10-09 (changed)
369
387
  ```
@@ -374,7 +392,7 @@ Book.import books, validate_uniqueness: true
374
392
 
375
393
  ### Return Info
376
394
 
377
- The `import` method returns a `Result` object that responds to `failed_instances` and `num_inserts`. Additionally, for users of Postgres, there will be two arrays `ids` and `results` that can be accessed`.
395
+ The `import` method returns a `Result` object that responds to `failed_instances` and `num_inserts`. Additionally, for users of Postgres, there will be two arrays `ids` and `results` that can be accessed.
378
396
 
379
397
  ```ruby
380
398
  articles = [
@@ -415,7 +433,9 @@ Should you wish to specify those columns, you may use the option `timestamps: fa
415
433
 
416
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`.
417
435
 
418
- 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**
438
+ > If you are using ActiveRecord 7.0 or later, please use `ActiveRecord.default_timezone` instead.
419
439
 
420
440
  ### Callbacks
421
441
 
@@ -487,7 +507,8 @@ This allows an external gem to dynamically add an adapter without the need to ad
487
507
 
488
508
  ### Requiring
489
509
 
490
- Note: These instructions will only work if you are using version 0.2.0 or higher.
510
+ > **Note**
511
+ > These instructions will only work if you are using version 0.2.0 or higher.
491
512
 
492
513
  #### Autoloading via Bundler
493
514
 
@@ -524,7 +545,7 @@ require 'activerecord-import'
524
545
  ### Load Path Setup
525
546
  To understand how rubygems loads code you can reference the following:
526
547
 
527
- http://guides.rubygems.org/patterns/#loading_code
548
+ http://guides.rubygems.org/patterns/#loading-code
528
549
 
529
550
  And an example of how active_record dynamically load adapters:
530
551
 
@@ -552,9 +573,9 @@ When rubygems pushes the `lib` folder onto the load path a `require` will now fi
552
573
 
553
574
  ### Conflicts With Other Gems
554
575
 
555
- `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.
576
+ 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.
556
577
 
557
- 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 explcitly setting this value within the model. For example:
578
+ 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:
558
579
 
559
580
  ```ruby
560
581
  class Post < ActiveRecord::Base
@@ -579,7 +600,7 @@ See https://github.com/zdennis/activerecord-import/issues/233 for further discus
579
600
 
580
601
  ### More Information
581
602
 
582
- For more information on activerecord-import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
603
+ For more information on Activerecord-Import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
583
604
 
584
605
  To document new information, please add to the README instead of the wiki. See https://github.com/zdennis/activerecord-import/issues/397 for discussion.
585
606
 
@@ -597,32 +618,22 @@ After that, you can run the tests. They run against multiple tests and ActiveRec
597
618
 
598
619
  This is one example of how to run the tests:
599
620
 
600
- ```ruby
621
+ ```bash
601
622
  rm Gemfile.lock
602
- AR_VERSION=4.2 bundle install
603
- AR_VERSION=4.2 bundle exec rake test:postgresql test:sqlite3 test:mysql2
623
+ AR_VERSION=7.0 bundle install
624
+ AR_VERSION=7.0 bundle exec rake test:postgresql test:sqlite3 test:mysql2
604
625
  ```
605
626
 
606
- Once you have pushed up your changes, you can find your CI results [here](https://travis-ci.org/zdennis/activerecord-import/).
627
+ Once you have pushed up your changes, you can find your CI results [here](https://github.com/zdennis/activerecord-import/actions).
628
+
629
+ ## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
630
+
631
+ 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).
607
632
 
608
633
  # License
609
634
 
610
- This is licensed under the ruby license.
635
+ This is licensed under the MIT license.
611
636
 
612
637
  # Author
613
638
 
614
639
  Zach Dennis (zach.dennis@gmail.com)
615
-
616
- # Contributors
617
-
618
- * Jordan Owens (@jkowens)
619
- * Erik Michaels-Ober (@sferik)
620
- * Blythe Dunham
621
- * Gabe da Silveira
622
- * Henry Work
623
- * James Herdman
624
- * Marcus Crafter
625
- * Thibaud Guillaume-Gentil
626
- * Mark Van Holstyn
627
- * Victor Costan
628
- * Dillon Welch
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler"
2
4
  Bundler.setup
3
5
 
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require File.expand_path('../lib/activerecord-import/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
@@ -6,8 +7,8 @@ Gem::Specification.new do |gem|
6
7
  gem.email = ["zach.dennis@gmail.com"]
7
8
  gem.summary = "Bulk insert extension for ActiveRecord"
8
9
  gem.description = "A library for bulk inserting data using ActiveRecord."
9
- gem.homepage = "http://github.com/zdennis/activerecord-import"
10
- gem.license = "Ruby"
10
+ gem.homepage = "https://github.com/zdennis/activerecord-import"
11
+ gem.license = "MIT"
11
12
 
12
13
  gem.files = `git ls-files`.split($\)
13
14
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -16,8 +17,8 @@ Gem::Specification.new do |gem|
16
17
  gem.require_paths = ["lib"]
17
18
  gem.version = ActiveRecord::Import::VERSION
18
19
 
19
- gem.required_ruby_version = ">= 1.9.2"
20
+ gem.required_ruby_version = ">= 2.4.0"
20
21
 
21
- gem.add_runtime_dependency "activerecord", ">= 3.2"
22
+ gem.add_runtime_dependency "activerecord", ">= 4.2"
22
23
  gem.add_development_dependency "rake"
23
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require "fileutils"
3
5
  require "active_record"
@@ -20,7 +22,11 @@ FileUtils.mkdir_p 'log'
20
22
  ActiveRecord::Base.configurations["test"] = YAML.load_file(File.join(benchmark_dir, "../test/database.yml"))[options.adapter]
21
23
  ActiveRecord::Base.logger = Logger.new("log/test.log")
22
24
  ActiveRecord::Base.logger.level = Logger::DEBUG
23
- ActiveRecord::Base.default_timezone = :utc
25
+ if ActiveRecord.respond_to?(:default_timezone)
26
+ ActiveRecord.default_timezone = :utc
27
+ else
28
+ ActiveRecord::Base.default_timezone = :utc
29
+ end
24
30
 
25
31
  require "activerecord-import"
26
32
  ActiveRecord::Base.establish_connection(:test)
@@ -35,7 +41,7 @@ require File.join(benchmark_dir, "../test/schema/generic_schema")
35
41
  adapter_schema = File.join(benchmark_dir, "schema/#{options.adapter}_schema.rb")
36
42
  require adapter_schema if File.exist?(adapter_schema)
37
43
 
38
- Dir[File.dirname(__FILE__) + "/models/*.rb"].each { |file| require file }
44
+ Dir["#{File.dirname(__FILE__)}/models/*.rb"].sort.each { |file| require file }
39
45
 
40
46
  require File.join( benchmark_dir, 'lib', "#{options.adapter}_benchmark" )
41
47
 
@@ -47,8 +53,8 @@ else
47
53
  end
48
54
 
49
55
  letter = options.adapter[0].chr
50
- clazz_str = letter.upcase + options.adapter[1..-1].downcase
51
- clazz = Object.const_get( clazz_str + "Benchmark" )
56
+ clazz_str = letter.upcase + options.adapter[1..].downcase
57
+ clazz = Object.const_get( "#{clazz_str}Benchmark" )
52
58
 
53
59
  benchmarks = []
54
60
  options.number_of_objects.each do |num|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class BenchmarkBase
2
4
  attr_reader :results
3
5
 
@@ -25,11 +27,11 @@ class BenchmarkBase
25
27
  # An OpenStruct object with the following attributes:
26
28
  # * description - the description of the benchmark ran
27
29
  # * tms - a Benchmark::Tms containing the results of the benchmark
28
- def bm( description )
30
+ def bm( description, &block )
29
31
  tms = nil
30
32
  puts "Benchmarking #{description}"
31
33
 
32
- Benchmark.bm { |x| tms = x.report { yield } }
34
+ Benchmark.bm { |x| tms = x.report(&block) }
33
35
  delete_all
34
36
  failed = false
35
37
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
  require 'ostruct'
3
5
 
@@ -8,7 +10,7 @@ require 'ostruct'
8
10
  # * t - the table types to test. ie: myisam, innodb, memory, temporary, etc.
9
11
  #
10
12
  module BenchmarkOptionParser
11
- BANNER = "Usage: ruby #{$0} [options]\nSee ruby #{$0} -h for more options.".freeze
13
+ BANNER = "Usage: ruby #{$0} [options]\nSee ruby #{$0} -h for more options."
12
14
 
13
15
  def self.print_banner
14
16
  puts BANNER
@@ -27,7 +29,7 @@ module BenchmarkOptionParser
27
29
  print_valid_table_types( options, prefix: " " )
28
30
  end
29
31
 
30
- # TODO IMPLEMENT THIS
32
+ # TODO: IMPLEMENT THIS
31
33
  def self.print_valid_table_types( options, hsh = { prefix: '' } )
32
34
  if !options.table_types.keys.empty?
33
35
  options.table_types.keys.sort.each { |type| puts hsh[:prefix].to_s + type.to_s }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Taken from http://www.programmingishard.com/posts/show/128
2
4
  # Posted by rbates
3
5
  class Float
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mysql2Benchmark < BenchmarkBase
2
4
  def benchmark_all( array_of_cols_and_vals )
3
5
  methods = self.methods.find_all { |m| m =~ /benchmark_/ }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
 
3
5
  module OutputToCSV
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'erb'
2
4
 
3
5
  module OutputToHTML
4
- TEMPLATE_HEADER = <<"EOT".freeze
6
+ TEMPLATE_HEADER = <<"EOT"
5
7
  <div>
6
8
  All times are rounded to the nearest thousandth for display purposes. Speedups next to each time are computed
7
9
  before any rounding occurs. Also, all speedup calculations are computed by comparing a given time against
@@ -9,7 +11,7 @@ module OutputToHTML
9
11
  </div>
10
12
  EOT
11
13
 
12
- TEMPLATE = <<"EOT".freeze
14
+ TEMPLATE = <<"EOT"
13
15
  <style>
14
16
  td#benchmarkTitle {
15
17
  border: 1px solid black;
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TestInnoDb < ActiveRecord::Base
2
4
  self.table_name = 'test_innodb'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TestMemory < ActiveRecord::Base
2
4
  self.table_name = 'test_memory'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TestMyISAM < ActiveRecord::Base
2
4
  self.table_name = 'test_myisam'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::Schema.define do
2
4
  create_table :test_myisam, options: 'ENGINE=MyISAM', force: true do |t|
3
5
  t.column :my_name, :string, null: false
data/gemfiles/4.2.gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem 'activerecord', '~> 4.2.0'
2
4
  gem 'composite_primary_keys', '~> 8.0'
data/gemfiles/5.0.gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem 'activerecord', '~> 5.0.0'
2
4
  gem 'composite_primary_keys', '~> 9.0'
data/gemfiles/5.1.gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem 'activerecord', '~> 5.1.0'
2
4
  gem 'composite_primary_keys', '~> 10.0'
data/gemfiles/5.2.gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem 'activerecord', '~> 5.2.0'
2
4
  gem 'composite_primary_keys', '~> 11.0'
data/gemfiles/6.0.gemfile CHANGED
@@ -1 +1,4 @@
1
- gem 'activerecord', '~> 6.0.0.rc1'
1
+ # frozen_string_literal: true
2
+
3
+ gem 'activerecord', '~> 6.0.0'
4
+ gem 'composite_primary_keys', '~> 12.0'
data/gemfiles/6.1.gemfile CHANGED
@@ -1 +1,4 @@
1
- gem 'activerecord', '~> 6.1.0.alpha'
1
+ # frozen_string_literal: true
2
+
3
+ gem 'activerecord', '~> 6.1.0'
4
+ gem 'composite_primary_keys', '~> 13.0'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem 'activerecord', '~> 7.0.0'
4
+ gem 'composite_primary_keys', '~> 14.0'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "activerecord-import/adapters/abstract_adapter"
2
4
 
3
5
  module ActiveRecord # :nodoc:
@@ -1,6 +1,8 @@
1
- require "active_record/connection_adapters/mysql_adapter"
2
- require "activerecord-import/adapters/mysql_adapter"
1
+ # frozen_string_literal: true
3
2
 
4
- class ActiveRecord::ConnectionAdapters::MysqlAdapter
5
- include ActiveRecord::Import::MysqlAdapter
3
+ require "active_record/connection_adapters/mysql2_adapter"
4
+ require "activerecord-import/adapters/mysql2_adapter"
5
+
6
+ class ActiveRecord::ConnectionAdapters::Mysql2Adapter
7
+ include ActiveRecord::Import::Mysql2Adapter
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/postgresql_adapter"
2
4
  require "activerecord-import/adapters/postgresql_adapter"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/sqlite3_adapter"
2
4
  require "activerecord-import/adapters/sqlite3_adapter"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/mysql2_adapter"
2
4
  require "activerecord-import/adapters/mysql2_adapter"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/postgresql_adapter"
2
4
  require "activerecord-import/adapters/postgresql_adapter"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "seamless_database_pool"
2
4
  require "active_record/connection_adapters/seamless_database_pool_adapter"
3
5
  require "activerecord-import/adapters/mysql_adapter"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/sqlite3_adapter"
2
4
  require "activerecord-import/adapters/sqlite3_adapter"
3
5