execute <<-SQL
commit
reindex database ActiveRecord::Base.configurations[Rails.env]['database']
SQL
明らかにそれは機能しませんが、アイデアはわかります。上記のコード構造が何と呼ばれているのか、調べてみてもわかりません。
Postgres ではトランザクション内での db reindex が許可されていないため、Rails 4 までトランザクションを無効にする方法がないように見えるため、上記のハックが機能することを願っています。
UPDATE
したがって、上記は機能しませんでしたが、このハックは機能しました:
# force a reindex after we switched all those columns to citext
execute "commit;"
execute "reindex database #{ActiveRecord::Base.configurations[Rails.env]['database']} force;"