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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34bd3f3fc2c18bc49962183603c7f2c85e167d978eafd3fb840b639fa98de60d
4
- data.tar.gz: 0ae0b82440ea7dcec1183c987395742fab0c93618b384f770d7acd3fecd41cdf
3
+ metadata.gz: 296a1517b032cbd6d5fa3948f60f1a4f20c4142c8f4c7676c43998f9e941925d
4
+ data.tar.gz: f61a7c6728a6ea1e834be61187b61e3ddf004f4314003752ec3ccf9a5b79afd9
5
5
  SHA512:
6
- metadata.gz: 321b877ffe09ccf2edb94b43d1060f5ebc8d83c1c058a41dc1d248f4d52c161b5a4576186363349c6c027d20890375728590271d24bdb75647d0556a57202aa9
7
- data.tar.gz: d6a25cf51e31b772e4556b18de85ed88c5019b0469a8d6299e955063042c2e939f4f3f228e05ce4fdc8a4060b2ee2f4160a1e5d477a8769439b103f03b103fb8
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 |relation, min_value, max_value|
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
- # For convenience in dev/test environments
376
- if Utils.developer_env?
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]) || start_id
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.13.0"
4
+ VERSION = "0.14.0"
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.13.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-22 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord