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 +4 -4
- data/lib/dekiru/data_migration/migration.rb +10 -4
- data/lib/dekiru/data_migration/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5005a000366972c658bdda144f38061ca3ccc165138e03fe80a258baa8d6b58
|
|
4
|
+
data.tar.gz: fe14a8ffcb9546bb6e02f9959f934d09640fbc5dbe99684a779549688dc04f05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|