online_migrations 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/docs/configuring.md +11 -0
- data/lib/generators/online_migrations/templates/initializer.rb.tt +4 -0
- data/lib/online_migrations/background_migrations/migration.rb +1 -4
- data/lib/online_migrations/background_migrations/migration_helpers.rb +2 -2
- data/lib/online_migrations/batch_iterator.rb +1 -1
- data/lib/online_migrations/config.rb +11 -0
- data/lib/online_migrations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 296a1517b032cbd6d5fa3948f60f1a4f20c4142c8f4c7676c43998f9e941925d
|
4
|
+
data.tar.gz: f61a7c6728a6ea1e834be61187b61e3ddf004f4314003752ec3ccf9a5b79afd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd04da6b57f9862726ee45e6ed13b1032632099a089e26e691717b2e93009269b7f8a8cf3c828501ef97a86d3d13731d4cadb77d0b48f0cf25fea172502780c1
|
7
|
+
data.tar.gz: '089a7f40afc28b9671669764ee98c760e4ee8649aab67a4d814b22ca8f5c52cf76afc8a5c9f95244d8be7b879d2b714fa38f07fff3c741bcc91e450077c96801'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.14.0 (2024-02-01)
|
4
|
+
|
5
|
+
- Add ability to configure whether background migrations should be run inline
|
6
|
+
|
7
|
+
The previous behavior of running inline in development and test environments is preserved, unless overriden.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
config.run_background_migrations_inline = -> { Rails.env.local? }
|
11
|
+
```
|
12
|
+
|
13
|
+
## 0.13.1 (2024-01-23)
|
14
|
+
|
15
|
+
- Fix calculation of batch ranges for background migration created with explicit ranges
|
16
|
+
|
3
17
|
## 0.13.0 (2024-01-22)
|
4
18
|
|
5
19
|
- Add ability to configure the path where generated background migrations will be placed
|
data/docs/configuring.md
CHANGED
@@ -214,6 +214,17 @@ Add to an initializer file:
|
|
214
214
|
config.auto_analyze = true
|
215
215
|
```
|
216
216
|
|
217
|
+
### Running background migrations inline
|
218
|
+
|
219
|
+
`config.run_background_migrations_inline` can be configured with a proc to decide whether background migrations should be run inline. For convenience defaults to true for development and test environments.
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
# config/initializers/online_migrations.rb
|
223
|
+
config.run_background_migrations_inline = -> { Rails.env.local? }
|
224
|
+
```
|
225
|
+
|
226
|
+
Set to `nil` to avoid running background migrations inline.
|
227
|
+
|
217
228
|
## Schema Sanity
|
218
229
|
|
219
230
|
Columns can flip order in `db/schema.rb` when you have multiple developers. One way to prevent this is to [alphabetize them](https://www.pgrs.net/2008/03/12/alphabetize-schema-rb-columns/).
|
@@ -77,6 +77,10 @@ OnlineMigrations.configure do |config|
|
|
77
77
|
# end
|
78
78
|
# end
|
79
79
|
|
80
|
+
# Decide whether background migrations should be run inline.
|
81
|
+
# Convenient for development and test environments.
|
82
|
+
config.run_background_migrations_inline = -> { Rails.env.local? }
|
83
|
+
|
80
84
|
# ==> Background migrations configuration
|
81
85
|
|
82
86
|
# The path where generated background migrations will be placed.
|
@@ -197,10 +197,7 @@ module OnlineMigrations
|
|
197
197
|
|
198
198
|
on_shard do
|
199
199
|
# rubocop:disable Lint/UnreachableLoop
|
200
|
-
iterator.each_batch(of: batch_size, column: batch_column_name, start: next_min_value) do |
|
201
|
-
if max_value.nil?
|
202
|
-
max_value = relation.pick(relation.arel_table[batch_column_name].maximum)
|
203
|
-
end
|
200
|
+
iterator.each_batch(of: batch_size, column: batch_column_name, start: next_min_value, finish: max_value) do |_relation, min_value, max_value|
|
204
201
|
batch_range = [min_value, max_value]
|
205
202
|
|
206
203
|
break
|
@@ -372,8 +372,8 @@ module OnlineMigrations
|
|
372
372
|
def enqueue_background_migration(migration_name, *arguments, **options)
|
373
373
|
migration = create_background_migration(migration_name, *arguments, **options)
|
374
374
|
|
375
|
-
|
376
|
-
if
|
375
|
+
run_inline = OnlineMigrations.config.run_background_migrations_inline
|
376
|
+
if run_inline && run_inline.call
|
377
377
|
runner = MigrationRunner.new(migration)
|
378
378
|
runner.run_all_migration_jobs
|
379
379
|
end
|
@@ -69,7 +69,7 @@ module OnlineMigrations
|
|
69
69
|
# efficient UPDATE queries, hence we get rid of it.
|
70
70
|
batch_relation = batch_relation.except(:order)
|
71
71
|
|
72
|
-
last_id = (last_row && last_row[column]) ||
|
72
|
+
last_id = (last_row && last_row[column]) || finish
|
73
73
|
|
74
74
|
# Retaining the results in the query cache would undermine the point of batching.
|
75
75
|
batch_relation.uncached { yield batch_relation, start_id, last_id }
|
@@ -171,6 +171,16 @@ module OnlineMigrations
|
|
171
171
|
#
|
172
172
|
attr_accessor :verbose_sql_logs
|
173
173
|
|
174
|
+
# The proc which decides whether background migrations should be run inline.
|
175
|
+
# For convenience defaults to true for development and test environments.
|
176
|
+
#
|
177
|
+
# @example
|
178
|
+
# OnlineMigrations.config.run_background_migrations_inline = -> { Rails.env.local? }
|
179
|
+
#
|
180
|
+
# @return [Proc]
|
181
|
+
#
|
182
|
+
attr_accessor :run_background_migrations_inline
|
183
|
+
|
174
184
|
# Configuration object to configure background migrations
|
175
185
|
#
|
176
186
|
# @return [BackgroundMigrationsConfig]
|
@@ -202,6 +212,7 @@ module OnlineMigrations
|
|
202
212
|
@alphabetize_schema = false
|
203
213
|
@enabled_checks = @error_messages.keys.index_with({})
|
204
214
|
@verbose_sql_logs = defined?(Rails.env) && (Rails.env.production? || Rails.env.staging?)
|
215
|
+
@run_background_migrations_inline = -> { Utils.developer_env? }
|
205
216
|
end
|
206
217
|
|
207
218
|
def lock_retrier=(value)
|
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.
|
4
|
+
version: 0.14.0
|
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
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|