mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-25 07:23:43 +01:00
Fix AddUniqueIndexOnPreviewCardsStatuses
migration requiring PostgreSQL 12+ in some cases (#26737)
This commit is contained in:
parent
6b58cfd8dd
commit
1471be8225
1 changed files with 13 additions and 1 deletions
|
@ -15,10 +15,22 @@ class AddUniqueIndexOnPreviewCardsStatuses < ActiveRecord::Migration[6.1]
|
|||
|
||||
private
|
||||
|
||||
def supports_concurrent_reindex?
|
||||
@supports_concurrent_reindex ||= begin
|
||||
version = select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
|
||||
version >= 12_000
|
||||
end
|
||||
end
|
||||
|
||||
def deduplicate_and_reindex!
|
||||
deduplicate_preview_cards!
|
||||
|
||||
safety_assured { execute 'REINDEX INDEX CONCURRENTLY preview_cards_statuses_pkey' }
|
||||
if supports_concurrent_reindex?
|
||||
safety_assured { execute 'REINDEX INDEX CONCURRENTLY preview_cards_statuses_pkey' }
|
||||
else
|
||||
remove_index :preview_cards_statuses, name: :preview_cards_statuses_pkey
|
||||
add_index :preview_cards_statuses, [:status_id, :preview_card_id], name: :preview_cards_statuses_pkey, algorithm: :concurrently, unique: true
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
retry
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue