Update `tootctl maintenance fix-duplicates` to Mastodon v4.2.0 (#27147)

This commit is contained in:
Claire 2023-09-26 11:11:52 +02:00 committed by GitHub
parent fdc9f971f7
commit 82eaa26d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -5,7 +5,7 @@ require_relative 'base'
module Mastodon::CLI module Mastodon::CLI
class Maintenance < Base class Maintenance < Base
MIN_SUPPORTED_VERSION = 2019_10_01_213028 MIN_SUPPORTED_VERSION = 2019_10_01_213028
MAX_SUPPORTED_VERSION = 2022_11_04_133904 MAX_SUPPORTED_VERSION = 2023_09_07_150100
# 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
@ -37,6 +37,8 @@ module Mastodon::CLI
class CanonicalEmailBlock < ApplicationRecord; end class CanonicalEmailBlock < ApplicationRecord; end
class Appeal < ApplicationRecord; end class Appeal < ApplicationRecord; end
class Webhook < ApplicationRecord; end class Webhook < ApplicationRecord; end
class BulkImport < ApplicationRecord; end
class SoftwareUpdate < ApplicationRecord; end
class PreviewCard < ApplicationRecord class PreviewCard < ApplicationRecord
self.inheritance_column = false self.inheritance_column = false
@ -86,6 +88,7 @@ module Mastodon::CLI
owned_classes << FollowRecommendationSuppression if ActiveRecord::Base.connection.table_exists?(:follow_recommendation_suppressions) owned_classes << FollowRecommendationSuppression if ActiveRecord::Base.connection.table_exists?(:follow_recommendation_suppressions)
owned_classes << AccountIdentityProof if ActiveRecord::Base.connection.table_exists?(:account_identity_proofs) owned_classes << AccountIdentityProof if ActiveRecord::Base.connection.table_exists?(:account_identity_proofs)
owned_classes << Appeal if ActiveRecord::Base.connection.table_exists?(:appeals) owned_classes << Appeal if ActiveRecord::Base.connection.table_exists?(:appeals)
owned_classes << BulkImport if ActiveRecord::Base.connection.table_exists?(:bulk_imports)
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|
@ -169,6 +172,7 @@ module Mastodon::CLI
deduplicate_tags! deduplicate_tags!
deduplicate_webauthn_credentials! deduplicate_webauthn_credentials!
deduplicate_webhooks! deduplicate_webhooks!
deduplicate_software_updates!
Scenic.database.refresh_materialized_view('instances', concurrently: true, cascade: false) if ActiveRecord::Migrator.current_version >= 2020_12_06_004238 Scenic.database.refresh_materialized_view('instances', concurrently: true, cascade: false) if ActiveRecord::Migrator.current_version >= 2020_12_06_004238
Rails.cache.clear Rails.cache.clear
@ -204,6 +208,7 @@ module Mastodon::CLI
ActiveRecord::Base.connection.execute('REINDEX INDEX search_index;') ActiveRecord::Base.connection.execute('REINDEX INDEX search_index;')
ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_uri;') ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_uri;')
ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_url;') ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_url;')
ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_domain_and_id;') if ActiveRecord::Migrator.current_version >= 2023_05_24_190515
end end
def deduplicate_users! def deduplicate_users!
@ -241,6 +246,8 @@ module Mastodon::CLI
else else
ActiveRecord::Base.connection.add_index :users, ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, where: 'reset_password_token IS NOT NULL', opclass: :text_pattern_ops ActiveRecord::Base.connection.add_index :users, ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, where: 'reset_password_token IS NOT NULL', opclass: :text_pattern_ops
end end
ActiveRecord::Base.connection.execute('REINDEX INDEX index_users_on_unconfirmed_email;') if ActiveRecord::Migrator.current_version >= 2023_07_02_151753
end end
def deduplicate_users_process_confirmation_token def deduplicate_users_process_confirmation_token
@ -541,6 +548,11 @@ module Mastodon::CLI
ActiveRecord::Base.connection.add_index :webhooks, ['url'], name: 'index_webhooks_on_url', unique: true ActiveRecord::Base.connection.add_index :webhooks, ['url'], name: 'index_webhooks_on_url', unique: true
end end
def deduplicate_software_updates!
# Not bothering with this, it's data that will be recovered with the scheduler
SoftwareUpdate.delete_all
end
def deduplicate_local_accounts!(accounts) def deduplicate_local_accounts!(accounts)
accounts = accounts.sort_by(&:id).reverse accounts = accounts.sort_by(&:id).reverse