discourse/db/migrate/20230113002617_reindex_invalid_indexes.rb
Selase Krakani bd2ca8d617
DEV: Promote historic post_deploy migrations (#25329)
This commit promotes all post_deploy migrations which existed in Discourse v3.1.0 (timestamp <= 20230405121454)
2024-01-19 13:59:20 +00:00

24 lines
595 B
Ruby

# frozen_string_literal: true
class ReindexInvalidIndexes < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
invalid_index_names = DB.query_single(<<~SQL)
SELECT
pg_class.relname
FROM pg_class, pg_index, pg_namespace
WHERE pg_index.indisvalid = false
AND pg_index.indexrelid = pg_class.oid
AND pg_namespace.nspname = 'public'
AND relnamespace = pg_namespace.oid;
SQL
invalid_index_names.each { |index_name| execute "REINDEX INDEX CONCURRENTLY #{index_name}" }
end
def down
raise ActiveRecord::IrreversibleMigration
end
end