mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 06:45:03 +08:00
6832c7b7e7
Follow up to 799a45a291
34 lines
1.0 KiB
Ruby
34 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class DropOldNotificationIdIndexes < ActiveRecord::Migration[7.0]
|
|
disable_ddl_transaction!
|
|
|
|
def up
|
|
# Drop old indexes
|
|
results =
|
|
execute(
|
|
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'notifications' AND indexdef SIMILAR TO '%\\mold_id\\M%'",
|
|
)
|
|
results.each do |res|
|
|
indexname, indexdef = res["indexname"], res["indexdef"]
|
|
execute "DROP INDEX #{Rails.env.test? ? "" : "CONCURRENTLY"} IF EXISTS #{indexname}"
|
|
end
|
|
|
|
# Remove `_bigint` suffix from indexes
|
|
results =
|
|
execute(
|
|
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'notifications' AND indexdef SIMILAR TO '%\\mid\\M%' AND schemaname = 'public'",
|
|
)
|
|
results.each do |res|
|
|
indexname, indexdef = res["indexname"], res["indexdef"]
|
|
if indexname.include?("_bigint")
|
|
execute "ALTER INDEX #{indexname} RENAME TO #{indexname.gsub(/_bigint$/, "")}"
|
|
end
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|