Update fix-duplicates maintenance script to support latest migrations (#16231)

* Update maintenance script to support latest database migrations

* Update Account#merge_with!
signup-info-prompt
Claire 2021-05-12 23:19:44 +02:00 committed by GitHub
parent 2840f995d5
commit 76064e6608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -15,7 +15,7 @@ module AccountMerging
Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite, Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite,
Follow, FollowRequest, Block, Mute, AccountIdentityProof, Follow, FollowRequest, Block, Mute, AccountIdentityProof,
AccountModerationNote, AccountPin, AccountStat, ListAccount, AccountModerationNote, AccountPin, AccountStat, ListAccount,
PollVote, Mention, AccountDeletionRequest, AccountNote PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression
] ]
owned_classes.each do |klass| owned_classes.each do |klass|
@ -43,6 +43,10 @@ module AccountMerging
end end
end end
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
record.update_attribute(:reference_account_id, id)
end
# Some follow relationships have moved, so the cache is stale # Some follow relationships have moved, so the cache is stale
Rails.cache.delete_matched("followers_hash:#{id}:*") Rails.cache.delete_matched("followers_hash:#{id}:*")
Rails.cache.delete_matched("relationships:#{id}:*") Rails.cache.delete_matched("relationships:#{id}:*")

View File

@ -14,7 +14,7 @@ module Mastodon
end end
MIN_SUPPORTED_VERSION = 2019_10_01_213028 MIN_SUPPORTED_VERSION = 2019_10_01_213028
MAX_SUPPORTED_VERSION = 2021_03_08_133107 MAX_SUPPORTED_VERSION = 2021_05_07_001928
# Stubs to enjoy ActiveRecord queries while not depending on a particular # Stubs to enjoy ActiveRecord queries while not depending on a particular
# version of the code/database # version of the code/database
@ -42,6 +42,8 @@ module Mastodon
class CustomEmojiCategory < ApplicationRecord; end class CustomEmojiCategory < ApplicationRecord; end
class Bookmark < ApplicationRecord; end class Bookmark < ApplicationRecord; end
class WebauthnCredential < ApplicationRecord; end class WebauthnCredential < ApplicationRecord; end
class FollowRecommendationSuppression < ApplicationRecord; end
class CanonicalEmailBlock < ApplicationRecord; end
class PreviewCard < ApplicationRecord class PreviewCard < ApplicationRecord
self.inheritance_column = false self.inheritance_column = false
@ -88,6 +90,7 @@ module Mastodon
] ]
owned_classes << AccountDeletionRequest if ActiveRecord::Base.connection.table_exists?(:account_deletion_requests) owned_classes << AccountDeletionRequest if ActiveRecord::Base.connection.table_exists?(:account_deletion_requests)
owned_classes << AccountNote if ActiveRecord::Base.connection.table_exists?(:account_notes) owned_classes << AccountNote if ActiveRecord::Base.connection.table_exists?(:account_notes)
owned_classes << FollowRecommendationSuppression if ActiveRecord::Base.connection.table_exists?(:follow_recommendation_suppressions)
owned_classes.each do |klass| owned_classes.each do |klass|
klass.where(account_id: other_account.id).find_each do |record| klass.where(account_id: other_account.id).find_each do |record|
@ -111,6 +114,12 @@ module Mastodon
end end
end end
end end
if ActiveRecord::Base.connection.table_exists?(:canonical_email_blocks)
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
record.update_attribute(:reference_account_id, id)
end
end
end end
end end
@ -466,6 +475,11 @@ module Mastodon
@prompt.say 'Restoring tags indexes…' @prompt.say 'Restoring tags indexes…'
ActiveRecord::Base.connection.add_index :tags, 'lower((name)::text)', name: 'index_tags_on_name_lower', unique: true ActiveRecord::Base.connection.add_index :tags, 'lower((name)::text)', name: 'index_tags_on_name_lower', unique: true
if ActiveRecord::Base.connection.indexes(:tags).any? { |i| i.name == 'index_tags_on_name_lower_btree' }
@prompt.say 'Reindexing textual indexes on tags…'
ActiveRecord::Base.connection.execute('REINDEX INDEX index_tags_on_name_lower_btree;')
end
end end
def deduplicate_webauthn_credentials! def deduplicate_webauthn_credentials!