online_migrations 0.19.6 → 0.20.1
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 +11 -1
- data/docs/configuring.md +1 -1
- data/lib/generators/online_migrations/templates/background_data_migration.rb.tt +9 -2
- data/lib/online_migrations/background_migrations/migration_job.rb +1 -1
- data/lib/online_migrations/background_migrations/migration_runner.rb +1 -1
- data/lib/online_migrations/background_schema_migrations/migration.rb +2 -2
- data/lib/online_migrations/batch_iterator.rb +2 -1
- data/lib/online_migrations/change_column_type_helpers.rb +2 -2
- data/lib/online_migrations/command_checker.rb +9 -7
- data/lib/online_migrations/database_tasks.rb +1 -1
- data/lib/online_migrations/error_messages.rb +2 -2
- data/lib/online_migrations/schema_statements.rb +2 -2
- 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: 2fd0059b044a120c61044268bfc32c3622163ae1871f85655ae51fe3cfb99c60
|
4
|
+
data.tar.gz: 1e1842002d3d229014011ee2a6af8eb122eaa7a6822912bec2d276f67e6555b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 590aa0a0d36f94316cf02c0b3c8ec2dcf7be08e17cd687eb889d6fb9d8a4cfc892424cffb49c1988691720a7cbede5d58f1a2e712a0ddd8ab8545ce6df6395ed
|
7
|
+
data.tar.gz: a981da87aae5a6e0a5872be04ec9839285fa6b53693c73a4f8ceac354d30f5623d7aef473a8d5c07992e14654083253d3603881f031877692c6718c8f5588407
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.20.1 (2024-11-05)
|
4
|
+
|
5
|
+
- Fix background data migrations to work with `includes`/`eager_load` on relation
|
6
|
+
- Fix problem with running migrations for `activerecord` 8.0.0.rc2
|
7
|
+
|
8
|
+
## 0.20.0 (2024-10-21)
|
9
|
+
|
10
|
+
- Enhance columns removal check to check indexes `where` and `include` options
|
11
|
+
- Do not wait before running retried background migrations
|
12
|
+
|
3
13
|
## 0.19.6 (2024-09-26)
|
4
14
|
|
5
|
-
- Fix `
|
15
|
+
- Fix `add_reference_concurrently` when adding non polymorphic references
|
6
16
|
- Fix progress for background migrations with small number of records
|
7
17
|
|
8
18
|
## 0.19.5 (2024-09-20)
|
data/docs/configuring.md
CHANGED
@@ -51,7 +51,7 @@ config.check_down = true
|
|
51
51
|
You can customize specific error messages:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
config.error_messages[:
|
54
|
+
config.error_messages[:add_column_with_default] = "Your custom instructions"
|
55
55
|
```
|
56
56
|
|
57
57
|
Check the [source code](https://github.com/fatkodima/online_migrations/blob/master/lib/online_migrations/error_messages.rb) for the list of keys.
|
@@ -4,18 +4,25 @@ module <%= migrations_module %>
|
|
4
4
|
<% module_namespacing do -%>
|
5
5
|
class <%= class_name %> < OnlineMigrations::BackgroundMigration
|
6
6
|
def relation
|
7
|
-
# ActiveRecord::Relation to be iterated over
|
7
|
+
# return ActiveRecord::Relation to be iterated over
|
8
8
|
end
|
9
9
|
|
10
10
|
def process_batch(relation)
|
11
|
+
# 'relation' is an ActiveRecord::Relation instance containing a batch to process.
|
12
|
+
#
|
11
13
|
# The work to be done in a single iteration of the background migration.
|
12
14
|
# This should be idempotent, as the same batch may be processed more
|
13
15
|
# than once if the background migration is interrupted and resumed.
|
14
16
|
end
|
15
17
|
|
18
|
+
# Optional.
|
16
19
|
def count
|
17
|
-
#
|
20
|
+
# Define the number of rows that will be iterated over.
|
18
21
|
# This is used to track the background migration's progress.
|
22
|
+
# Usually this is configured to be 'relation.count'.
|
23
|
+
#
|
24
|
+
# If the query to calculate the count is heavy, it is recommended to use
|
25
|
+
# some approximate hardcode number or skip defining this method entirely.
|
19
26
|
end
|
20
27
|
end
|
21
28
|
<% end -%>
|
@@ -17,7 +17,7 @@ module OnlineMigrations
|
|
17
17
|
scope :completed, -> { where(status: [:failed, :succeeded]) }
|
18
18
|
scope :stuck, -> do
|
19
19
|
timeout = OnlineMigrations.config.background_migrations.stuck_jobs_timeout
|
20
|
-
|
20
|
+
running.where("updated_at <= ?", timeout.seconds.ago)
|
21
21
|
end
|
22
22
|
|
23
23
|
scope :retriable, -> do
|
@@ -115,7 +115,7 @@ module OnlineMigrations
|
|
115
115
|
if min_value && max_value
|
116
116
|
create_migration_job!(min_value, max_value)
|
117
117
|
else
|
118
|
-
migration.migration_jobs.retriable.first
|
118
|
+
migration.migration_jobs.enqueued.first || migration.migration_jobs.retriable.first
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -123,7 +123,7 @@ module OnlineMigrations
|
|
123
123
|
return false if composite?
|
124
124
|
|
125
125
|
stuck_timeout = (statement_timeout || 1.day) + 10.minutes
|
126
|
-
|
126
|
+
running? && updated_at <= stuck_timeout.seconds.ago
|
127
127
|
end
|
128
128
|
|
129
129
|
# Mark this migration as ready to be processed again.
|
@@ -134,7 +134,7 @@ module OnlineMigrations
|
|
134
134
|
if composite? && failed?
|
135
135
|
children.failed.each(&:retry)
|
136
136
|
update!(
|
137
|
-
status: self.class.statuses[:
|
137
|
+
status: self.class.statuses[:enqueued],
|
138
138
|
finished_at: nil
|
139
139
|
)
|
140
140
|
true
|
@@ -19,7 +19,8 @@ module OnlineMigrations
|
|
19
19
|
end
|
20
20
|
|
21
21
|
relation = apply_limits(self.relation, column, start, finish, order)
|
22
|
-
|
22
|
+
unscopes = Utils.ar_version < 7.1 ? [:includes] : [:includes, :preload, :eager_load]
|
23
|
+
base_relation = relation.unscope(*unscopes).reselect(column).reorder(column => order)
|
23
24
|
|
24
25
|
start_id = start || begin
|
25
26
|
start_row = base_relation.uncached { base_relation.first }
|
@@ -118,7 +118,7 @@ module OnlineMigrations
|
|
118
118
|
type_cast_functions[column_name] = type_cast_function if type_cast_function
|
119
119
|
tmp_column_name = conversions[column_name]
|
120
120
|
|
121
|
-
if
|
121
|
+
if database_version >= 11_00_00
|
122
122
|
if primary_key(table_name) == column_name.to_s && old_col.type == :integer
|
123
123
|
# For PG < 11 and Primary Key conversions, setting a column as the PK
|
124
124
|
# converts even check constraints to NOT NULL column constraints
|
@@ -497,7 +497,7 @@ module OnlineMigrations
|
|
497
497
|
def __set_not_null(table_name, column_name)
|
498
498
|
# For PG >= 12 we can "promote" CHECK constraint to NOT NULL constraint:
|
499
499
|
# https://github.com/postgres/postgres/commit/bbb96c3704c041d139181c6601e5bc770e045d26
|
500
|
-
if
|
500
|
+
if database_version >= 12_00_00
|
501
501
|
execute(<<~SQL)
|
502
502
|
ALTER TABLE #{quote_table_name(table_name)}
|
503
503
|
ALTER #{quote_column_name(column_name)}
|
@@ -453,13 +453,7 @@ module OnlineMigrations
|
|
453
453
|
|
454
454
|
if !new_table?(table_name)
|
455
455
|
indexes = connection.indexes(table_name).select do |index|
|
456
|
-
|
457
|
-
when String
|
458
|
-
# Expression index
|
459
|
-
columns.any? { |column| index.columns.include?(column) }
|
460
|
-
else
|
461
|
-
(index.columns & columns).any?
|
462
|
-
end
|
456
|
+
columns.any? { |column| index_include_column?(index, column) }
|
463
457
|
end
|
464
458
|
|
465
459
|
raise_error :remove_column,
|
@@ -892,6 +886,14 @@ module OnlineMigrations
|
|
892
886
|
postgresql_version < Gem::Version.new("14.4")
|
893
887
|
end
|
894
888
|
|
889
|
+
def index_include_column?(index, column)
|
890
|
+
# Expression index
|
891
|
+
(index.columns.is_a?(String) && index.columns.include?(column)) ||
|
892
|
+
index.columns.include?(column) ||
|
893
|
+
(Utils.ar_version >= 7.1 && index.include && index.include.include?(column)) ||
|
894
|
+
(index.where && index.where.include?(column))
|
895
|
+
end
|
896
|
+
|
895
897
|
def run_custom_checks(method, args)
|
896
898
|
OnlineMigrations.config.checks.each do |options, check|
|
897
899
|
if !options[:start_after] || version > options[:start_after]
|
@@ -279,8 +279,8 @@ end",
|
|
279
279
|
|
280
280
|
remove_column:
|
281
281
|
"<% if !small_table && indexes.any? %>
|
282
|
-
Removing a column will automatically remove all
|
283
|
-
|
282
|
+
Removing a column will automatically remove all the indexes that include this column.
|
283
|
+
Indexes will be removed non-concurrently, so you need to safely remove them first:
|
284
284
|
|
285
285
|
class <%= migration_name %>RemoveIndexes < <%= migration_parent %>
|
286
286
|
disable_ddl_transaction!
|
@@ -439,7 +439,7 @@ module OnlineMigrations
|
|
439
439
|
def add_column_with_default(table_name, column_name, type, **options)
|
440
440
|
default = options.fetch(:default)
|
441
441
|
|
442
|
-
if
|
442
|
+
if database_version >= 11_00_00 && !Utils.volatile_default?(self, type, default)
|
443
443
|
add_column(table_name, column_name, type, **options)
|
444
444
|
else
|
445
445
|
__ensure_not_in_transaction!
|
@@ -465,7 +465,7 @@ module OnlineMigrations
|
|
465
465
|
add_not_null_constraint(table_name, column_name, validate: false)
|
466
466
|
validate_not_null_constraint(table_name, column_name)
|
467
467
|
|
468
|
-
if
|
468
|
+
if database_version >= 12_00_00
|
469
469
|
# In PostgreSQL 12+ it is safe to "promote" a CHECK constraint to `NOT NULL` for the column
|
470
470
|
change_column_null(table_name, column_name, false)
|
471
471
|
remove_not_null_constraint(table_name, column_name)
|
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.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|