-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: create new conditional indexes _before_ dropping overlapping ind…
…exes Fixes issue introduced in #1163
- Loading branch information
1 parent
777ddfe
commit 2be784d
Showing
5 changed files
with
92 additions
and
56 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
demo/db/migrate/20231128075428_recreate_good_job_cron_indexes.rb
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
demo/db/migrate/20231128075428_recreate_good_job_cron_indexes_with_conditional.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class RecreateGoodJobCronIndexesWithConditional < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond) | ||
add_index :good_jobs, [:cron_key, :created_at], where: "(cron_key IS NOT NULL)", | ||
name: :index_good_jobs_on_cron_key_and_created_at_cond, algorithm: :concurrently | ||
end | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond) | ||
add_index :good_jobs, [:cron_key, :cron_at], where: "(cron_key IS NOT NULL)", unique: true, | ||
name: :index_good_jobs_on_cron_key_and_cron_at_cond, algorithm: :concurrently | ||
end | ||
|
||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at | ||
end | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at | ||
end | ||
end | ||
|
||
dir.down do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at) | ||
add_index :good_jobs, [:cron_key, :created_at], | ||
name: :index_good_jobs_on_cron_key_and_created_at, algorithm: :concurrently | ||
end | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
add_index :good_jobs, [:cron_key, :cron_at], unique: true, | ||
name: :index_good_jobs_on_cron_key_and_cron_at, algorithm: :concurrently | ||
end | ||
|
||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at_cond | ||
end | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at_cond | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
lib/generators/good_job/templates/update/migrations/07_recreate_good_job_cron_indexes.rb.erb
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...job/templates/update/migrations/07_recreate_good_job_cron_indexes_with_conditional.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class RecreateGoodJobCronIndexesWithConditional < ActiveRecord::Migration<%= migration_version %> | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond) | ||
add_index :good_jobs, [:cron_key, :created_at], where: "(cron_key IS NOT NULL)", | ||
name: :index_good_jobs_on_cron_key_and_created_at_cond, algorithm: :concurrently | ||
end | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond) | ||
add_index :good_jobs, [:cron_key, :cron_at], where: "(cron_key IS NOT NULL)", unique: true, | ||
name: :index_good_jobs_on_cron_key_and_cron_at_cond, algorithm: :concurrently | ||
end | ||
|
||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at | ||
end | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at | ||
end | ||
end | ||
|
||
dir.down do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at) | ||
add_index :good_jobs, [:cron_key, :created_at], where: "(cron_key IS NOT NULL)", | ||
name: :index_good_jobs_on_cron_key_and_created_at, algorithm: :concurrently | ||
end | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
add_index :good_jobs, [:cron_key, :cron_at], where: "(cron_key IS NOT NULL)", unique: true, | ||
name: :index_good_jobs_on_cron_key_and_cron_at, algorithm: :concurrently | ||
end | ||
|
||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at_cond | ||
end | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond) | ||
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at_cond | ||
end | ||
end | ||
end | ||
end | ||
end |