dekiru-data_migration 1.3.0 → 1.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b46a5373c84760557f19d957cdc79d285e1c11812090007b4ccc2dfd7d81cb82
4
- data.tar.gz: a3ba1a45dc98df3ba559adefcfbda99ccab9cc76e64ea83cd94f3f815d5541df
3
+ metadata.gz: f5005a000366972c658bdda144f38061ca3ccc165138e03fe80a258baa8d6b58
4
+ data.tar.gz: fe14a8ffcb9546bb6e02f9959f934d09640fbc5dbe99684a779549688dc04f05
5
5
  SHA512:
6
- metadata.gz: 3febccaa7208f1375ef412fcb77c48450d613733900130b6f388e4ae5e099aa0dc4787ab6877cc13769d442cf21ceb21ed058e364423e6a862d49ec3ecc151c9
7
- data.tar.gz: 6e39a7f6148affaa5e50461e32cf546cde57dcda1e6409a705c6ff617904116c70689d5e71df6233f8fd73e4a430074efbcdfe2c4875b3b8d8adfbaf681633ca
6
+ metadata.gz: e765f1ac06542de3b8598fe66ac42c16ea89b0b1a6b09da4071e713e5da0f36fd2239b321ea37452da21f4d450ec321196159187407a6ba1c4d56880b869b03a
7
+ data.tar.gz: 92492fe777e9454d6fd2ab45c55268268403403e21a0242377643b3ea49ce3e8e4c75a44eec1b227acc8cb99beff97f67849ba529e81a85858afd12e74ca400c
@@ -4,6 +4,9 @@ module Dekiru
4
4
  module DataMigration
5
5
  # Base class for data migration with testable method separation
6
6
  class Migration
7
+ # Default batch size used by ActiveRecord's `in_batches` when `of:` is not given
8
+ DEFAULT_BATCH_SIZE = 1000
9
+
7
10
  attr_accessor :batch_size
8
11
 
9
12
  def self.run(options = {})
@@ -26,11 +29,12 @@ module Dekiru
26
29
  def migrate
27
30
  targets = migration_targets
28
31
 
29
- log "Target count: #{targets.count}"
32
+ target_count = targets.count
33
+ log "Target count: #{target_count}"
30
34
  confirm?
31
35
 
32
36
  if migrate_batch_overridden?
33
- migrate_in_batches(targets)
37
+ migrate_in_batches(targets, target_count)
34
38
  else
35
39
  migrate_each_record(targets)
36
40
  end
@@ -52,9 +56,11 @@ module Dekiru
52
56
 
53
57
  private
54
58
 
55
- def migrate_in_batches(targets)
59
+ def migrate_in_batches(targets, target_count)
60
+ size = batch_size || DEFAULT_BATCH_SIZE
56
61
  batches = batch_size ? targets.in_batches(of: batch_size) : targets.in_batches
57
- each_with_progress(batches) do |batch|
62
+ total = (target_count.to_f / size).ceil
63
+ each_with_progress(batches, total: total) do |batch|
58
64
  migrate_batch(batch)
59
65
  end
60
66
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dekiru
4
4
  module DataMigration
5
- VERSION = "1.3.0"
5
+ VERSION = "1.3.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dekiru-data_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden