online_migrations 0.19.6 → 0.20.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: cd8711d56259535675633074868019a5c4b3de068bb30d783c9ae16dc906afb1
4
- data.tar.gz: 3b417e176d143092d69e4551c1f96a32e1a2acf1d74d268fc33f9b5a598be553
3
+ metadata.gz: d945b90fafc0b4f1c47139e5e4ffc35440e92abcbb84b07f19664f04c3beb5ac
4
+ data.tar.gz: 6e0f18f9f36f05cdc8d41b884df73facd22e935baa314622e4710fbf7412df7f
5
5
  SHA512:
6
- metadata.gz: ad26fd5662f2636479b697933042b8d7e60b4ee42f136ddeb8cff8256c65a4491b8017d09d2da849faf65cb6f8d4ecc95595816b7669c8364e9f31bbe75232c4
7
- data.tar.gz: 21fec027462ff6f96baaf0fc65d186fc68fefbb50fd3de6af8f561aae691e6f9909d70d7053557d39f0a56ea498841816c2853cce0b1acef161411b2d968b196
6
+ metadata.gz: 799963762ca1ad74807132428ac30aa04b2c36734227c273fa74fd2cc7d0f59a2e483dd94616f83040885b0b6b217d3ae8334fbb28ba39968447572e178d69bf
7
+ data.tar.gz: e1fc78f999f6d98037a1435564875b7c35a522af7ef993fdf0a791376a9528e069322f5a67c96cc769d7ed1a6c16ccdccd24f238f441da9f692fb8c14dca2826
data/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.20.0 (2024-10-21)
4
+
5
+ - Enhance columns removal check to check indexes `where` and `include` options
6
+ - Do not wait before running retried background migrations
7
+
3
8
  ## 0.19.6 (2024-09-26)
4
9
 
5
- - Fix `add_refernce_concurrently` when adding non polymorphic references
10
+ - Fix `add_reference_concurrently` when adding non polymorphic references
6
11
  - Fix progress for background migrations with small number of records
7
12
 
8
13
  ## 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[:add_column_default] = "Your custom instructions"
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
- # Optionally, define the number of rows that will be iterated over.
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
- active.where("updated_at <= ?", timeout.seconds.ago)
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
- (enqueued? || running?) && updated_at <= stuck_timeout.seconds.ago
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[:running],
137
+ status: self.class.statuses[:enqueued],
138
138
  finished_at: nil
139
139
  )
140
140
  true
@@ -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 raw_connection.server_version >= 11_00_00
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 raw_connection.server_version >= 12_00_00
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
- case index.columns
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 of the indexes that involved the removed column.
283
- But the indexes would be removed non-concurrently, so you need to safely remove the indexes first:
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 raw_connection.server_version >= 11_00_00 && !Utils.volatile_default?(self, type, default)
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 raw_connection.server_version >= 12_00_00
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.19.6"
4
+ VERSION = "0.20.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.19.6
4
+ version: 0.20.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-09-26 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord