online_migrations 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ceda570f99a1712496ac5c9549859c7dc2cad7e3cc4ab59c97a22ba17f3bfd0
4
- data.tar.gz: dfc5a83147a92bf5e04a532210e72b6f32f561f032b2a1b746ff142bf4e16635
3
+ metadata.gz: c08a823ebaea1855fcfaae87c3252cbc4a727f04ae564cd14cfcb8e2f43ebb2b
4
+ data.tar.gz: f02621f945b90de34217f588d26a243b506bc47c9433feab784b8db43ecd83de
5
5
  SHA512:
6
- metadata.gz: 0ff6cce820134ef6b893f9405b71a0d8f8cd42dd79616123aaa492983671ebcff98dbff21477afa78b29342d40098822da4b8de0306489faf956b21ee44e2113
7
- data.tar.gz: 42dcf132290c9affe812ef7489397d4c05d48f33069f3ee09710fced6aaf8ac928fee63c1498333657a824f98885e3af5e706e4dcc4a089b9cd62284ad0223d1
6
+ metadata.gz: 7bb01d066a03e7bb85c6d6e37f6c3e67351dc1a890579d9eb4c8ef7a200785918c863a7b2f1104a1d531772da0405daa1f9724cad6b224a92da08fba3fac2479
7
+ data.tar.gz: 21acc8fbfb9a2aab13d5768f1df613d74e9145d55148bdb8b04b53e5687bca9fd0e6f88178282dec9f0642fdad2fd188e979d152b697b771554adf866aa417e3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.11.1 (2024-01-11)
4
+
5
+ - Fix calculation of batch ranges for sharded background migrations
6
+
3
7
  ## 0.11.0 (2024-01-09)
4
8
 
5
9
  - Support sharding for background migrations
@@ -102,9 +102,15 @@ module OnlineMigrations
102
102
  if succeeded?
103
103
  100.0
104
104
  elsif composite?
105
- progresses = children.map(&:progress).compact
106
- if progresses.any?
107
- (progresses.sum / progresses.size).round(2)
105
+ rows_counts = children.to_a.pluck(:rows_count)
106
+ if rows_counts.none?(nil)
107
+ total_rows_count = rows_counts.sum
108
+
109
+ progresses = children.map do |child|
110
+ child.progress * child.rows_count / total_rows_count # weighted progress
111
+ end
112
+
113
+ progresses.sum.round(2)
108
114
  end
109
115
  elsif rows_count
110
116
  jobs_rows_count = migration_jobs.succeeded.sum(:batch_size)
@@ -181,15 +187,17 @@ module OnlineMigrations
181
187
  iterator = BatchIterator.new(migration_relation)
182
188
  batch_range = nil
183
189
 
184
- # rubocop:disable Lint/UnreachableLoop
185
- iterator.each_batch(of: batch_size, column: batch_column_name, start: next_min_value) do |relation|
186
- min = relation.arel_table[batch_column_name].minimum
187
- max = relation.arel_table[batch_column_name].maximum
188
- batch_range = relation.pick(min, max)
190
+ on_shard do
191
+ # rubocop:disable Lint/UnreachableLoop
192
+ iterator.each_batch(of: batch_size, column: batch_column_name, start: next_min_value) do |relation|
193
+ min = relation.arel_table[batch_column_name].minimum
194
+ max = relation.arel_table[batch_column_name].maximum
195
+ batch_range = relation.pick(min, max)
189
196
 
190
- break
197
+ break
198
+ end
199
+ # rubocop:enable Lint/UnreachableLoop
191
200
  end
192
- # rubocop:enable Lint/UnreachableLoop
193
201
 
194
202
  return if batch_range.nil?
195
203
 
@@ -286,7 +294,7 @@ module OnlineMigrations
286
294
  attributes.each do |attribute|
287
295
  updates[attribute] = read_attribute(attribute) if attribute_changed?(attribute)
288
296
  end
289
- children.update_all(updates) if updates.any?
297
+ children.active.update_all(updates) if updates.any?
290
298
  end
291
299
 
292
300
  def next_min_value
@@ -14,10 +14,7 @@ module OnlineMigrations
14
14
  def run_migration_job
15
15
  raise "Should not be called on a composite (with sharding) migration" if migration.composite?
16
16
 
17
- if migration.enqueued?
18
- migration.running!
19
- migration.parent.running! if migration.parent && migration.parent.enqueued?
20
- end
17
+ mark_as_running if migration.enqueued?
21
18
  migration_payload = notifications_payload(migration)
22
19
 
23
20
  if !migration.migration_jobs.exists?
@@ -57,7 +54,7 @@ module OnlineMigrations
57
54
  raise "This method is not intended for use in production environments" if !Utils.developer_env?
58
55
  return if migration.completed?
59
56
 
60
- migration.running!
57
+ mark_as_running
61
58
 
62
59
  if migration.composite?
63
60
  migration.children.each do |child_migration|
@@ -96,6 +93,11 @@ module OnlineMigrations
96
93
  end
97
94
 
98
95
  private
96
+ def mark_as_running
97
+ migration.running!
98
+ migration.parent.running! if migration.parent && migration.parent.enqueued?
99
+ end
100
+
99
101
  def should_throttle?
100
102
  ::OnlineMigrations.config.background_migrations.throttler.call
101
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.11.0"
4
+ VERSION = "0.11.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: online_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.4.10
107
+ rubygems_version: 3.5.4
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Catch unsafe PostgreSQL migrations in development and run them easier in