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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +3 -2
- data/docs/configuring.md +1 -1
- data/lib/generators/online_migrations/templates/background_migrations_change_status_default.rb.tt +1 -1
- data/lib/generators/online_migrations/templates/initializer.rb.tt +1 -1
- data/lib/online_migrations/background_data_migrations/scheduler.rb +10 -4
- data/lib/online_migrations/background_schema_migrations/migration.rb +28 -18
- data/lib/online_migrations/config.rb +1 -1
- data/lib/online_migrations/error_messages.rb +4 -16
- data/lib/online_migrations/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: 54cc719e4b9c6d22226c4393fa81362cec973f1f368553c2797bc5a7e0b3720b
|
|
4
|
+
data.tar.gz: f8dba7a97c0e4bbb744d552f783ad9407aa65aec16d1020933becaf83a9779a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 `
|
|
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
|
|
445
|
-
(is disabled by default in Active Record >= 7),
|
|
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 `
|
|
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
|
data/lib/generators/online_migrations/templates/background_migrations_change_status_default.rb.tt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
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 #
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
170
|
+
connection.execute(definition)
|
|
172
171
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
|
|
@@ -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
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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.",
|