Merge remote-tracking branch 'parent/main' into upstream-20230209

This commit is contained in:
KMY 2024-02-09 12:53:59 +09:00
commit 05e52a09a8
188 changed files with 2810 additions and 1295 deletions

View file

@ -1,12 +1,6 @@
# frozen_string_literal: true
MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
ActiveRecord::Migration[5.0]
else
ActiveRecord::Migration[4.2]
end
class RailsSettingsMigration < MIGRATION_BASE_CLASS
class RailsSettingsMigration < ActiveRecord::Migration[5.0]
def self.up
create_table :settings do |t|
t.string :var, null: false

View file

@ -2,7 +2,17 @@
class AddSearchIndexToAccounts < ActiveRecord::Migration[5.0]
def up
execute 'CREATE INDEX search_index ON accounts USING gin((setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\')));'
execute <<~SQL.squish
CREATE INDEX search_index
ON accounts
USING gin(
(
setweight(to_tsvector('simple', accounts.display_name), 'A') ||
setweight(to_tsvector('simple', accounts.username), 'B') ||
setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C')
)
)
SQL
end
def down

View file

@ -7,80 +7,73 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
include Mastodon::MigrationHelpers
include Mastodon::MigrationWarning
TABLE_COLUMN_MAPPING = [
[:account_domain_blocks, :account_id],
[:account_domain_blocks, :id],
[:accounts, :id],
[:blocks, :account_id],
[:blocks, :id],
[:blocks, :target_account_id],
[:conversation_mutes, :account_id],
[:conversation_mutes, :id],
[:domain_blocks, :id],
[:favourites, :account_id],
[:favourites, :id],
[:favourites, :status_id],
[:follow_requests, :account_id],
[:follow_requests, :id],
[:follow_requests, :target_account_id],
[:follows, :account_id],
[:follows, :id],
[:follows, :target_account_id],
[:imports, :account_id],
[:imports, :id],
[:media_attachments, :account_id],
[:media_attachments, :id],
[:mentions, :account_id],
[:mentions, :id],
[:mutes, :account_id],
[:mutes, :id],
[:mutes, :target_account_id],
[:notifications, :account_id],
[:notifications, :from_account_id],
[:notifications, :id],
[:oauth_access_grants, :application_id],
[:oauth_access_grants, :id],
[:oauth_access_grants, :resource_owner_id],
[:oauth_access_tokens, :application_id],
[:oauth_access_tokens, :id],
[:oauth_access_tokens, :resource_owner_id],
[:oauth_applications, :id],
[:oauth_applications, :owner_id],
[:reports, :account_id],
[:reports, :action_taken_by_account_id],
[:reports, :id],
[:reports, :target_account_id],
[:session_activations, :access_token_id],
[:session_activations, :user_id],
[:session_activations, :web_push_subscription_id],
[:settings, :id],
[:settings, :thing_id],
[:statuses, :account_id],
[:statuses, :application_id],
[:statuses, :in_reply_to_account_id],
[:stream_entries, :account_id],
[:stream_entries, :id],
[:subscriptions, :account_id],
[:subscriptions, :id],
[:tags, :id],
[:users, :account_id],
[:users, :id],
[:web_settings, :id],
[:web_settings, :user_id],
].freeze
disable_ddl_transaction!
def migrate_columns(to_type)
included_columns = [
[:account_domain_blocks, :account_id],
[:account_domain_blocks, :id],
[:accounts, :id],
[:blocks, :account_id],
[:blocks, :id],
[:blocks, :target_account_id],
[:conversation_mutes, :account_id],
[:conversation_mutes, :id],
[:domain_blocks, :id],
[:favourites, :account_id],
[:favourites, :id],
[:favourites, :status_id],
[:follow_requests, :account_id],
[:follow_requests, :id],
[:follow_requests, :target_account_id],
[:follows, :account_id],
[:follows, :id],
[:follows, :target_account_id],
[:imports, :account_id],
[:imports, :id],
[:media_attachments, :account_id],
[:media_attachments, :id],
[:mentions, :account_id],
[:mentions, :id],
[:mutes, :account_id],
[:mutes, :id],
[:mutes, :target_account_id],
[:notifications, :account_id],
[:notifications, :from_account_id],
[:notifications, :id],
[:oauth_access_grants, :application_id],
[:oauth_access_grants, :id],
[:oauth_access_grants, :resource_owner_id],
[:oauth_access_tokens, :application_id],
[:oauth_access_tokens, :id],
[:oauth_access_tokens, :resource_owner_id],
[:oauth_applications, :id],
[:oauth_applications, :owner_id],
[:reports, :account_id],
[:reports, :action_taken_by_account_id],
[:reports, :id],
[:reports, :target_account_id],
[:session_activations, :access_token_id],
[:session_activations, :user_id],
[:session_activations, :web_push_subscription_id],
[:settings, :id],
[:settings, :thing_id],
[:statuses, :account_id],
[:statuses, :application_id],
[:statuses, :in_reply_to_account_id],
[:stream_entries, :account_id],
[:stream_entries, :id],
[:subscriptions, :account_id],
[:subscriptions, :id],
[:tags, :id],
[:users, :account_id],
[:users, :id],
[:web_settings, :id],
[:web_settings, :user_id],
]
included_columns << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards)
display_warning
migration_duration_warning(<<~EXPLANATION)
This migration has some sections that can be safely interrupted
and restarted later, and will tell you when those are occurring.
For more information, see https://github.com/mastodon/mastodon/pull/5088
EXPLANATION
tables = included_columns.map(&:first).uniq
table_sizes = {}
# Sort tables by their size
@ -103,6 +96,25 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
end
end
def display_warning
migration_duration_warning(<<~EXPLANATION)
This migration has some sections that can be safely interrupted
and restarted later, and will tell you when those are occurring.
For more information, see https://github.com/mastodon/mastodon/pull/5088
EXPLANATION
end
def tables
included_columns.map(&:first).uniq
end
def included_columns
TABLE_COLUMN_MAPPING.dup.tap do |included_columns|
included_columns << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards)
end
end
def up
migrate_columns(:bigint)
end

View file

@ -9,9 +9,32 @@ class AddCaseInsensitiveIndexToTags < ActiveRecord::Migration[5.2]
redundant_tag_ids = row['ids'].split(',')[1..]
safety_assured do
execute "UPDATE accounts_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)"
execute "UPDATE statuses_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM statuses_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.status_id = t0.status_id)"
execute "UPDATE featured_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM featured_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)"
execute <<~SQL.squish
UPDATE accounts_tags
AS t0
SET tag_id = #{canonical_tag_id}
WHERE
tag_id IN (#{redundant_tag_ids.join(', ')})
AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)
SQL
execute <<~SQL.squish
UPDATE statuses_tags
AS t0
SET tag_id = #{canonical_tag_id}
WHERE
tag_id IN (#{redundant_tag_ids.join(', ')})
AND NOT EXISTS (SELECT t1.tag_id FROM statuses_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.status_id = t0.status_id)
SQL
execute <<~SQL.squish
UPDATE featured_tags
AS t0
SET tag_id = #{canonical_tag_id}
WHERE
tag_id IN (#{redundant_tag_ids.join(', ')})
AND NOT EXISTS (SELECT t1.tag_id FROM featured_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)
SQL
end
Tag.where(id: redundant_tag_ids).in_batches.delete_all

View file

@ -3,13 +3,26 @@
class FixCanonicalEmailBlocksForeignKey < ActiveRecord::Migration[6.1]
def up
safety_assured do
execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id) ON DELETE CASCADE;'
execute <<~SQL.squish
ALTER TABLE canonical_email_blocks
DROP CONSTRAINT fk_rails_1ecb262096,
ADD CONSTRAINT fk_rails_1ecb262096
FOREIGN KEY (reference_account_id)
REFERENCES accounts(id)
ON DELETE CASCADE
SQL
end
end
def down
safety_assured do
execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id);'
execute <<~SQL.squish
ALTER TABLE canonical_email_blocks
DROP CONSTRAINT fk_rails_1ecb262096,
ADD CONSTRAINT fk_rails_1ecb262096
FOREIGN KEY (reference_account_id)
REFERENCES accounts(id)
SQL
end
end
end

View file

@ -4,7 +4,16 @@ class FixReblogDeletedAt < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
safety_assured { execute 'UPDATE statuses s SET deleted_at = r.deleted_at FROM statuses r WHERE s.reblog_of_id = r.id AND r.deleted_at IS NOT NULL' }
safety_assured do
execute <<~SQL.squish
UPDATE statuses s
SET deleted_at = r.deleted_at
FROM statuses r
WHERE
s.reblog_of_id = r.id
AND r.deleted_at IS NOT NULL
SQL
end
end
def down; end