DEV: Protection for migrations that creates index concurrently take 2 (#31792)

This is a follow up to 6820622467ab3613e824f0cb6219def2a575bc1d.

This commit addresses migrations that uses `remove_index` with the
`if_exists: true` option to drop an existing index before creating an
index using the `concurrently` option.

This commit also reruns two migration which may have caused indexes to
be left in an `invalid` state.

### Reviewers Note

Plugin tests are failing due to
https://github.com/discourse/discourse-translator/pull/251
This commit is contained in:
Alan Guo Xiang Tan
2025-03-17 08:25:30 +08:00
committed by GitHub
parent 0ebd0a0bd5
commit 02b8aa6096
7 changed files with 142 additions and 43 deletions

View File

@ -1,9 +0,0 @@
# frozen_string_literal: true
class AddIndexToUsersIpAddress < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_index :users, :ip_address, algorithm: :concurrently, name: "idx_users_ip_address"
end
end

View File

@ -1,10 +1,21 @@
# frozen_string_literal: true
class RemoveUniqueConstraintFromTagUsersIndexes < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
remove_index :tag_users, name: :idx_tag_users_ix1, algorithm: :concurrently
remove_index :tag_users, name: :idx_tag_users_ix2, algorithm: :concurrently
remove_index :tag_users, name: :idx_tag_users_ix1, algorithm: :concurrently, if_exists: true
remove_index :tag_users, name: :idx_tag_users_ix2, algorithm: :concurrently, if_exists: true
remove_index :tag_users,
%i[user_id tag_id notification_level],
algorithm: :concurrently,
if_exists: true
remove_index :tag_users,
%i[tag_id user_id notification_level],
algorithm: :concurrently,
if_exists: true
add_index :tag_users, %i[user_id tag_id notification_level], algorithm: :concurrently
add_index :tag_users, %i[tag_id user_id notification_level], algorithm: :concurrently

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
class AddIndexToUsersIpAddress < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
remove_index :users,
:ip_address,
algorithm: :concurrently,
name: "idx_users_ip_address",
if_exists: true
add_index :users, :ip_address, algorithm: :concurrently, name: "idx_users_ip_address"
end
def down
raise ActiveRecord::IrreversibleMigration
end
end