online_migrations 0.5.3 → 0.5.4
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/BACKGROUND_MIGRATIONS.md +3 -3
- data/CHANGELOG.md +4 -0
- data/README.md +5 -1
- data/lib/generators/online_migrations/templates/initializer.rb.tt +8 -8
- data/lib/online_migrations/background_migrations/config.rb +2 -2
- data/lib/online_migrations/command_checker.rb +2 -1
- data/lib/online_migrations/config.rb +1 -1
- 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: 974e87c3442a03f1a954a338678589549ed5c91fd293a7b4b5a8bad5ba807f32
|
4
|
+
data.tar.gz: 1b1dacee542413f623d74e947f704f57fa93a032f5b26c06d3ffc3dec105cc99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b4f245c656915711ffb2cb9c1a79f0a4a5a52374c38f01b0cd97a6a0bc06e803b5772ecb4cad36aef6f2dc5b97f543f66c35bcb1b195792c301746fc80c888c
|
7
|
+
data.tar.gz: 908f3c213a86b4e7fd48e9120c603c80f68facaa210827fd6ff60637a2b2e62241171f17706fe60cfecc324b318b227575d777a3d988299277f137ecdde0b48f
|
data/BACKGROUND_MIGRATIONS.md
CHANGED
@@ -120,7 +120,7 @@ enqueue_background_migration("MyMigrationWithArgs", arg1, arg2, ...)
|
|
120
120
|
* `CopyColumn` - copies data from one column(s) to other(s) (enqueue using `copy_column_in_background`)
|
121
121
|
* `DeleteAssociatedRecords` - deletes records associated with a parent object (enqueue using `delete_associated_records_in_background`)
|
122
122
|
* `DeleteOrphanedRecords` - deletes records with one or more missing relations (enqueue using `delete_orphaned_records_in_background`)
|
123
|
-
* `PerformActionOnRelation` - performs specific action on a relation or
|
123
|
+
* `PerformActionOnRelation` - performs specific action on a relation or individual records (enqueue using `perform_action_on_relation_in_background`)
|
124
124
|
* `ResetCounters` - resets one or more counter caches to their correct value (enqueue using `reset_counters_in_background`)
|
125
125
|
|
126
126
|
## Testing
|
@@ -240,7 +240,7 @@ Specify the throttle condition as a block:
|
|
240
240
|
```ruby
|
241
241
|
# config/initializers/online_migrations.rb
|
242
242
|
|
243
|
-
OnlineMigrations.config.
|
243
|
+
OnlineMigrations.config.background_migrations.throttler = -> { DatabaseStatus.unhealthy? }
|
244
244
|
```
|
245
245
|
|
246
246
|
Note that it's up to you to define a throttling condition that makes sense for your app. For example, you can check various PostgreSQL metrics such as replication lag, DB threads, whether DB writes are available, etc.
|
@@ -254,7 +254,7 @@ If you want to integrate with an exception monitoring service (e.g. Bugsnag), yo
|
|
254
254
|
```ruby
|
255
255
|
# config/initializers/online_migrations.rb
|
256
256
|
|
257
|
-
OnlineMigrations.config.
|
257
|
+
OnlineMigrations.config.background_migrations.error_handler = ->(error, errored_job) do
|
258
258
|
Bugsnag.notify(error) do |notification|
|
259
259
|
notification.add_metadata(:background_migration, { name: errored_job.migration_name })
|
260
260
|
end
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -69,7 +69,7 @@ class AddAdminToUsers < ActiveRecord::Migration[7.0]
|
|
69
69
|
# Do not wrap the migration in a transaction so that locks are held for a shorter time.
|
70
70
|
disable_ddl_transaction!
|
71
71
|
|
72
|
-
def
|
72
|
+
def up
|
73
73
|
# Lower PostgreSQL's lock timeout to avoid statement queueing.
|
74
74
|
execute "SET lock_timeout TO '5s'" # The lock_timeout duration is customizable.
|
75
75
|
|
@@ -88,6 +88,10 @@ class AddAdminToUsers < ActiveRecord::Migration[7.0]
|
|
88
88
|
execute "SET statement_timeout TO '5s'"
|
89
89
|
change_column_null :users, :admin, false
|
90
90
|
end
|
91
|
+
|
92
|
+
def down
|
93
|
+
remove_column :users, :admin
|
94
|
+
end
|
91
95
|
end
|
92
96
|
```
|
93
97
|
|
@@ -38,7 +38,7 @@ OnlineMigrations.configure do |config|
|
|
38
38
|
# migration failure in production. This is also useful in development to get
|
39
39
|
# a better grasp of what is going on for high-level statements like add_column_with_default.
|
40
40
|
#
|
41
|
-
# Note: It can be
|
41
|
+
# Note: It can be overridden by `ONLINE_MIGRATIONS_VERBOSE_SQL_LOGS` environment variable.
|
42
42
|
config.verbose_sql_logs = defined?(Rails) && Rails.env.production?
|
43
43
|
|
44
44
|
# Lock retries.
|
@@ -67,25 +67,25 @@ OnlineMigrations.configure do |config|
|
|
67
67
|
|
68
68
|
# ==> Background migrations configuration
|
69
69
|
# The number of rows to process in a single background migration run.
|
70
|
-
# config.
|
70
|
+
# config.background_migrations.batch_size = 20_000
|
71
71
|
|
72
72
|
# The smaller batches size that the batches will be divided into.
|
73
|
-
# config.
|
73
|
+
# config.background_migrations.sub_batch_size = 1000
|
74
74
|
|
75
75
|
# The pause interval between each background migration job's execution (in seconds).
|
76
|
-
# config.
|
76
|
+
# config.background_migrations.batch_pause = 0.seconds
|
77
77
|
|
78
78
|
# The number of milliseconds to sleep between each sub_batch execution.
|
79
|
-
# config.
|
79
|
+
# config.background_migrations.sub_batch_pause_ms = 100
|
80
80
|
|
81
81
|
# Maximum number of batch run attempts.
|
82
82
|
# When attempts are exhausted, the individual batch is marked as failed.
|
83
|
-
# config.
|
83
|
+
# config.background_migrations.batch_max_attempts = 5
|
84
84
|
|
85
85
|
# Configure custom throttler for background migrations.
|
86
86
|
# It will be called before each batch run.
|
87
87
|
# If throttled, the current run will be retried next time.
|
88
|
-
# config.
|
88
|
+
# config.background_migrations.throttler = -> { DatabaseStatus.unhealthy? }
|
89
89
|
|
90
90
|
# The number of seconds that must pass before the running job is considered stuck.
|
91
91
|
# config.background_migrations.stuck_jobs_timeout = 1.hour
|
@@ -95,7 +95,7 @@ OnlineMigrations.configure do |config|
|
|
95
95
|
config.background_migrations.backtrace_cleaner = Rails.backtrace_cleaner
|
96
96
|
|
97
97
|
# The callback to perform when an error occurs in the migration job.
|
98
|
-
# config.
|
98
|
+
# config.background_migrations.error_handler = ->(error, errored_job) do
|
99
99
|
# Bugsnag.notify(error) do |notification|
|
100
100
|
# notification.add_metadata(:background_migration, { name: errored_job.migration_name })
|
101
101
|
# end
|
@@ -43,7 +43,7 @@ module OnlineMigrations
|
|
43
43
|
# @return [Proc]
|
44
44
|
#
|
45
45
|
# @example
|
46
|
-
# OnlineMigrations.config.
|
46
|
+
# OnlineMigrations.config.background_migrations.throttler = -> { DatabaseStatus.unhealthy? }
|
47
47
|
#
|
48
48
|
attr_reader :throttler
|
49
49
|
|
@@ -64,7 +64,7 @@ module OnlineMigrations
|
|
64
64
|
# The callback to perform when an error occurs in the migration job.
|
65
65
|
#
|
66
66
|
# @example
|
67
|
-
# OnlineMigrations.config.
|
67
|
+
# OnlineMigrations.config.background_migrations.error_handler = ->(error, errored_job) do
|
68
68
|
# Bugsnag.notify(error) do |notification|
|
69
69
|
# notification.add_metadata(:background_migration, { name: errored_job.migration_name })
|
70
70
|
# end
|
@@ -42,6 +42,7 @@ module OnlineMigrations
|
|
42
42
|
|
43
43
|
true
|
44
44
|
end
|
45
|
+
ruby2_keywords(:check) if respond_to?(:ruby2_keywords, true)
|
45
46
|
|
46
47
|
private
|
47
48
|
def check_database_version
|
@@ -271,7 +272,7 @@ module OnlineMigrations
|
|
271
272
|
!options[:limit] || (existing_column.limit && options[:limit] >= existing_column.limit)
|
272
273
|
end
|
273
274
|
when :numeric, :decimal
|
274
|
-
# numeric and decimal are equivalent and can be used
|
275
|
+
# numeric and decimal are equivalent and can be used interchangeably
|
275
276
|
[:numeric, :decimal].include?(existing_type) &&
|
276
277
|
(
|
277
278
|
(
|
@@ -153,7 +153,7 @@ module OnlineMigrations
|
|
153
153
|
# This feature is enabled by default in a production Rails environment.
|
154
154
|
# @return [Boolean]
|
155
155
|
#
|
156
|
-
# @note: It can be
|
156
|
+
# @note: It can be overridden by `ONLINE_MIGRATIONS_VERBOSE_SQL_LOGS` environment variable.
|
157
157
|
#
|
158
158
|
attr_accessor :verbose_sql_logs
|
159
159
|
|
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.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|