discourse/db/migrate/20250313045010_add_index_to_users_ip_address.rb
Alan Guo Xiang Tan 02b8aa6096
DEV: Protection for migrations that creates index concurrently take 2 (#31792)
This is a follow up to 6820622467.

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
2025-03-17 08:25:30 +08:00

19 lines
473 B
Ruby

# 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