online_migrations 0.33.1 → 0.33.2

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: 5ea2552d8a879bacf5a5f8360a13aeafa9b36bec50943b359eb2d0501532ceb0
4
- data.tar.gz: 251b3bee148c70f37d86892ce985a93ee664a2623111de38b9fcff47b6be4baa
3
+ metadata.gz: 54cc719e4b9c6d22226c4393fa81362cec973f1f368553c2797bc5a7e0b3720b
4
+ data.tar.gz: f8dba7a97c0e4bbb744d552f783ad9407aa65aec16d1020933becaf83a9779a4
5
5
  SHA512:
6
- metadata.gz: 295c89b41757157ce16b7b2585d3516cd2900b1ba0291523c2e689991002669e08ba3928fc23b1047a92dbd0f225436f0b2f8ed9c7b6803fee8a4e56c4ef4239
7
- data.tar.gz: 16c0ada6d9a4e07271eae3a1a509f23a4756a5af3eebf172ca4971680b1c799f148c2f7bbeeffdcfce2e600cf24095e1663f03d6de00dd692af803ccdad22f62
6
+ metadata.gz: bd3a4195693d1f48a585c96ec66a0ae5775f585a2ce66c2e226a1148847cc63292e64a9704268a7a40e84a094c50e6a1990b91009fc22527db4ba004ef8aae95
7
+ data.tar.gz: 8f8cf24be5a12a4e68dadaeae47373a05ed2426bcc61f7bbe325e3e714c884ee353c48afd7696b7da3bd0393a2c88e11993afa081b99a63bedf839fb88e8eec4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.33.2 (2026-03-16)
4
+
5
+ - Fix message for adding to `ignored_columns` when renaming a column
6
+ - Schedule background data migration jobs only after committing the database transaction
7
+
3
8
  ## 0.33.1 (2026-02-05)
4
9
 
5
10
  - Allow "running" to "enqueued" state transition for stuck background data migrations
@@ -94,7 +99,7 @@
94
99
  - Drop support for Ruby < 3.1 and Rails < 7.1
95
100
  - Add check for `change_column` for columns with check constraints
96
101
 
97
- - Allow to require safety reason explanation when calling `safery_assured`
102
+ - Allow to require safety reason explanation when calling `safety_assured`
98
103
 
99
104
  ```ruby
100
105
  # config/initializers/online_migrations.rb
data/README.md CHANGED
@@ -441,8 +441,9 @@ It will use a combination of a VIEW and column aliasing to work with both column
441
441
  ```
442
442
 
443
443
  4. Replace usages of the old column with a new column in the codebase
444
- 5. If you enabled Active Record `enumerate_columns_in_select_statements` setting in your application
445
- (is disabled by default in Active Record >= 7), then you need to ignore old column:
444
+ 5. If the model has `ignored_columns` set, or you enabled Active Record
445
+ `enumerate_columns_in_select_statements` setting (is disabled by default in Active Record >= 7),
446
+ then you need to ignore the old column:
446
447
 
447
448
  ```ruby
448
449
  class User < ApplicationRecord
data/docs/configuring.md CHANGED
@@ -40,7 +40,7 @@ Check the [source code](https://github.com/fatkodima/online_migrations/blob/mast
40
40
 
41
41
  ## Requiring safety_assured reason
42
42
 
43
- To require safety reason explanation when calling `safery_assured` (disabled by default):
43
+ To require safety reason explanation when calling `safety_assured` (disabled by default):
44
44
 
45
45
  ```ruby
46
46
  config.require_safety_assured_reason = true
@@ -1,4 +1,4 @@
1
- class BackgroundDataMigrationsChangeStatusDefault < <%= migration_parent %>
1
+ class BackgroundMigrationsChangeStatusDefault < <%= migration_parent %>
2
2
  def change
3
3
  safety_assured do
4
4
  change_column_default :background_data_migrations, :status, from: "enqueued", to: "pending"
@@ -12,7 +12,7 @@ OnlineMigrations.configure do |config|
12
12
  # Set the version of the production database so the right checks are run in development.
13
13
  # config.target_version = 17
14
14
 
15
- # Configure whether to require safety reason explanation when calling #safery_assured.
15
+ # Configure whether to require safety reason explanation when calling #safety_assured.
16
16
  config.require_safety_assured_reason = false
17
17
 
18
18
  # Configure whether to perform checks when migrating down.
@@ -33,6 +33,8 @@ module OnlineMigrations
33
33
  relation = Migration.queue_order
34
34
  relation = relation.where(shard: shard) if shard
35
35
 
36
+ migrations_to_enqueue = []
37
+
36
38
  with_lock do
37
39
  stuck_migrations, active_migrations = relation.running.partition(&:stuck?)
38
40
  runnable_migrations = relation.pending + stuck_migrations
@@ -40,13 +42,18 @@ module OnlineMigrations
40
42
  # Ensure no more than 'concurrency' migrations are running at the same time.
41
43
  remaining_to_enqueue = concurrency - active_migrations.count
42
44
  if remaining_to_enqueue > 0
43
- migrations_to_enqueue = runnable_migrations.take(remaining_to_enqueue)
44
- migrations_to_enqueue.each do |migration|
45
- enqueue_migration(migration)
45
+ runnable_migrations.take(remaining_to_enqueue).each do |migration|
46
+ migration.update!(status: :enqueued)
47
+
48
+ migrations_to_enqueue << migration
46
49
  end
47
50
  end
48
51
  end
49
52
 
53
+ migrations_to_enqueue.each do |migration|
54
+ enqueue_migration(migration)
55
+ end
56
+
50
57
  true
51
58
  end
52
59
 
@@ -67,7 +74,6 @@ module OnlineMigrations
67
74
  def enqueue_migration(migration)
68
75
  job = OnlineMigrations.config.background_data_migrations.job
69
76
  job_class = job.constantize
70
- migration.update!(status: :enqueued)
71
77
 
72
78
  jid = job_class.perform_async(migration.id)
73
79
  if jid
@@ -151,28 +151,28 @@ module OnlineMigrations
151
151
  # @private
152
152
  def run
153
153
  on_shard_if_present do
154
- connection = connection_class.connection
155
-
156
- connection.with_lock_retries do
157
- statement_timeout = self.statement_timeout || OnlineMigrations.config.statement_timeout
158
-
159
- with_statement_timeout(connection, statement_timeout) do
160
- if index_addition?
161
- index = connection.indexes(table_name).find { |i| name.match?(/\b#{i.name}\b/) }
162
- if index
163
- if index.valid?
164
- return
165
- else
166
- connection.remove_index(table_name, name: index.name, algorithm: :concurrently)
154
+ with_connection do |connection|
155
+ connection.with_lock_retries do
156
+ statement_timeout = self.statement_timeout || OnlineMigrations.config.statement_timeout
157
+
158
+ with_statement_timeout(connection, statement_timeout) do
159
+ if index_addition?
160
+ index = connection.indexes(table_name).find { |i| name.match?(/\b#{i.name}\b/) }
161
+ if index
162
+ if index.valid?
163
+ return
164
+ else
165
+ connection.remove_index(table_name, name: index.name, algorithm: :concurrently)
166
+ end
167
167
  end
168
168
  end
169
- end
170
169
 
171
- connection.execute(definition)
170
+ connection.execute(definition)
172
171
 
173
- # Outdated statistics + a new index can hurt performance of existing queries.
174
- if OnlineMigrations.config.auto_analyze
175
- connection.execute("ANALYZE #{table_name}")
172
+ # Outdated statistics + a new index can hurt performance of existing queries.
173
+ if OnlineMigrations.config.auto_analyze
174
+ connection.execute("ANALYZE #{table_name}")
175
+ end
176
176
  end
177
177
  end
178
178
  end
@@ -206,6 +206,16 @@ module OnlineMigrations
206
206
  indexes_in_progress.include?(name)
207
207
  end
208
208
 
209
+ # Extension point, do not remove this method.
210
+ def with_connection(&block)
211
+ if Utils.ar_version >= 7.2
212
+ # https://github.com/rails/rails/pull/51083
213
+ connection_class.with_connection(&block)
214
+ else
215
+ yield connection_class.connection
216
+ end
217
+ end
218
+
209
219
  def with_statement_timeout(connection, timeout)
210
220
  return yield if timeout.nil?
211
221
 
@@ -73,7 +73,7 @@ module OnlineMigrations
73
73
  end
74
74
  end
75
75
 
76
- # Whether to require safety reason explanation when calling #safery_assured
76
+ # Whether to require safety reason explanation when calling #safety_assured
77
77
  #
78
78
  # Disabled by default
79
79
  # @return [Boolean]
@@ -148,14 +148,14 @@ It will use a combination of a VIEW and column aliasing to work with both column
148
148
  end
149
149
 
150
150
  4. Replace usages of the old column with a new column in the codebase
151
- <% if ActiveRecord::Base.enumerate_columns_in_select_statements %>
152
- 5. Ignore old column
151
+ 5. If the model has `ignored_columns` set, or you enabled
152
+ `enumerate_columns_in_select_statements`, ignore the old column:
153
153
 
154
154
  self.ignored_columns += [:<%= column_name %>]
155
155
 
156
156
  6. Deploy
157
157
  7. Remove the column rename config from step 1
158
- 8. Remove the column ignore from step 5
158
+ 8. Remove the column ignore from step 5, if added
159
159
  9. Remove the VIEW created in step 3 and finally rename the column:
160
160
 
161
161
  class Finalize<%= migration_name %> < <%= migration_parent %>
@@ -165,19 +165,7 @@ It will use a combination of a VIEW and column aliasing to work with both column
165
165
  end
166
166
 
167
167
  10. Deploy
168
- <% else %>
169
- 5. Deploy
170
- 6. Remove the column rename config from step 1
171
- 7. Remove the VIEW created in step 3 and finally rename the column:
172
-
173
- class Finalize<%= migration_name %> < <%= migration_parent %>
174
- def change
175
- finalize_column_rename :<%= table_name %>, :<%= column_name %>, :<%= new_column %>
176
- end
177
- end
178
-
179
- 8. Deploy
180
- <% end %>",
168
+ ",
181
169
 
182
170
  change_column_with_not_null:
183
171
  "Changing the type is safe, but setting NOT NULL is not.",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.33.1"
4
+ VERSION = "0.33.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: online_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.1
4
+ version: 0.33.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima