Revert "Upstream 20240517"

This commit is contained in:
KMY(雪あすか) 2024-05-24 08:15:12 +09:00 committed by GitHub
parent 9c006fd893
commit f6dec44e95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2347 changed files with 26470 additions and 87494 deletions

View file

@ -3,9 +3,7 @@
class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
class UserRole < ApplicationRecord
EVERYONE_ROLE_ID = -99
end
class UserRole < ApplicationRecord; end
def up
process_role_everyone
@ -19,7 +17,7 @@ class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
private
def process_role_everyone
everyone_role = UserRole.find_by(id: UserRole::EVERYONE_ROLE_ID)
everyone_role = UserRole.find_by(id: -99)
return unless everyone_role
everyone_role.permissions &= ~::UserRole::FLAGS[:invite_users] unless min_invite_role == 'user'

View file

@ -1,9 +0,0 @@
# frozen_string_literal: true
class RemoveGroupMessageFollowingOnlyFromAccounts < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
safety_assured { remove_column :accounts, :group_message_following_only, :boolean }
end
end

View file

@ -17,7 +17,8 @@ class AddUniqueIndexOnPreviewCardsStatuses < ActiveRecord::Migration[6.1]
def supports_concurrent_reindex?
@supports_concurrent_reindex ||= begin
ActiveRecord::Base.connection.database_version >= 120_000
version = select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
version >= 120_000
end
end

View file

@ -6,7 +6,7 @@ class DropFollowRecommendations < ActiveRecord::Migration[7.0]
end
def down
create_view :follow_recommendations, version: 2, materialized: true
create_view :follow_recommendations, version: 2, materialized: { no_data: true }
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
end
end

View file

@ -1,21 +0,0 @@
# frozen_string_literal: true
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class RemoveRemoteUriFromLocalCustomEmojis < ActiveRecord::Migration[7.0]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
class CustomEmoji < ApplicationRecord; end
def up
safety_assured do
CustomEmoji.transaction do
CustomEmoji.where(domain: nil).update_all(image_remote_url: nil, uri: nil)
end
end
end
def down; end
end

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class AddStatusesQuoteIndex < ActiveRecord::Migration[7.0]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
def change
safety_assured { add_index :statuses, [:quote_of_id, :account_id], unique: false }
end
end

View file

@ -1,18 +0,0 @@
# frozen_string_literal: true
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class RemoveLegacyDomainBlockColumns < ActiveRecord::Migration[7.1]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
def change
safety_assured do
remove_column :domain_blocks, :reject_send_not_public_searchability, :boolean, null: false, default: false
remove_column :domain_blocks, :reject_send_public_unlisted, :boolean, null: false, default: false
remove_column :domain_blocks, :reject_send_dissubscribable, :boolean, null: false, default: false
remove_column :domain_blocks, :reject_send_media, :boolean, null: false, default: false
end
end
end

View file

@ -1,28 +0,0 @@
# frozen_string_literal: true
class FixUriIndexToEmojiReactions < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
class EmojiReaction < ApplicationRecord
end
def up
# Remove duplications (very old kmyblue code [2023/03-04] maybe made some duplications)
duplications = EmojiReaction.where('uri IN (SELECT uri FROM emoji_reactions GROUP BY uri HAVING COUNT(*) > 1)')
.to_a.group_by(&:uri).to_h
if duplications.any?
EmojiReaction.transaction do
duplications.each do |h|
h[1].drop(1).each(&:destroy)
end
end
end
add_index :emoji_reactions, :uri, unique: true, algorithm: :concurrently
end
def down
remove_index :emoji_reactions, :uri
end
end

View file

@ -1,11 +0,0 @@
# frozen_string_literal: true
class ImproveRemotePendingAccountsIndex < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
remove_index :accounts, :remote_pending, unique: false, algorithm: :concurrently
add_index :accounts, :id, name: 'index_remote_pending_users', unique: false, algorithm: :concurrently, where: 'domain IS NOT NULL AND remote_pending AND suspended_at IS NOT NULL'
end
end

View file

@ -1,9 +0,0 @@
# frozen_string_literal: true
class IndexToSortForNgWordCreatedDate < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_index :ngword_histories, :created_at, algorithm: :concurrently
end
end

View file

@ -1,39 +0,0 @@
# frozen_string_literal: true
class MigrateDeviseTwoFactorSecrets < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
class MigrationUser < ApplicationRecord
self.table_name = :users
devise :two_factor_authenticatable,
otp_secret_encryption_key: Rails.configuration.x.otp_secret
include LegacyOtpSecret # Must be after the above `devise` line in order to override the legacy method
end
def up
MigrationUser.reset_column_information
users_with_otp_enabled.find_each do |user|
# Gets the new value on already-updated users
# Falls back to legacy value on not-yet-migrated users
otp_secret = user.otp_secret
Rails.logger.debug { "Processing #{user.email}" }
# This is a no-op for migrated users and updates format for not migrated
user.update!(otp_secret: otp_secret)
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
private
def users_with_otp_enabled
MigrationUser.where(otp_required_for_login: true, otp_secret: nil)
end
end

View file

@ -1,54 +0,0 @@
# frozen_string_literal: true
class MigrateInteractionSettingsToPolicyAgain < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
# Dummy classes, to make migration possible across version changes
class User < ApplicationRecord
belongs_to :notification_policy, foreign_key: 'account_id', primary_key: 'account_id', optional: true, inverse_of: false
end
class NotificationPolicy < ApplicationRecord; end
def up
User.includes(:notification_policy).in_batches do |users|
NotificationPolicy.insert_all(users.filter_map { |user| policy_for_user(user) })
end
end
def down; end
private
def policy_for_user(user)
deserialized_settings = Oj.load(user.attributes_before_type_cast['settings'])
return if deserialized_settings.nil?
return if user.notification_policy.present?
requires_new_policy = false
policy = {
account_id: user.account_id,
filter_not_followers: false,
filter_not_following: false,
filter_private_mentions: true,
}
if deserialized_settings['interactions.must_be_follower']
policy[:filter_not_followers] = true
requires_new_policy = true
end
if deserialized_settings['interactions.must_be_following']
policy[:filter_not_following] = true
requires_new_policy = true
end
unless deserialized_settings['interactions.must_be_following_dm']
policy[:filter_private_mentions] = false
requires_new_policy = true
end
policy if requires_new_policy
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
class RemoveRelationshipsCountFromAccountRelationshipSeveranceEvents < ActiveRecord::Migration[7.1]
def change
safety_assured { remove_column :account_relationship_severance_events, :relationships_count, :integer, default: 0, null: false }
end
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
class RemoveObsoleteRolesFromUsers < ActiveRecord::Migration[7.1]
def change
safety_assured { remove_column :users, :admin, :boolean, default: false, null: false }
safety_assured { remove_column :users, :moderator, :boolean, default: false, null: false }
end
end

View file

@ -1,10 +0,0 @@
# frozen_string_literal: true
class ImprovePreviewCardsVacuum < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_index :preview_cards, :id, name: 'index_preview_cards_vacuum', where: "image_file_name IS NOT NULL AND image_file_name <> ''", algorithm: :concurrently
add_index :media_attachments, :id, name: 'index_media_attachments_vacuum', where: "file_file_name IS NOT NULL AND remote_url <> ''", algorithm: :concurrently
end
end

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
class FixDuplicateIndicesForKmyblueOriginalFunctions < ActiveRecord::Migration[7.1]
def change
remove_index :antenna_accounts, :antenna_id
remove_index :antenna_domains, :antenna_id
remove_index :antenna_tags, :antenna_id
remove_index :bookmark_category_statuses, :bookmark_category_id
remove_index :circle_accounts, :circle_id
remove_index :circle_statuses, :circle_id
remove_index :list_statuses, :list_id
end
end