Move length value mapping to constant in ids to bigints migration (#29048)

This commit is contained in:
Matt Jankowski 2024-02-06 06:40:24 -05:00 committed by GitHub
parent 4cf07ed78c
commit dedefdc303
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,10 +7,7 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
include Mastodon::MigrationHelpers include Mastodon::MigrationHelpers
include Mastodon::MigrationWarning include Mastodon::MigrationWarning
disable_ddl_transaction! TABLE_COLUMN_MAPPING = [
def migrate_columns(to_type)
included_columns = [
[:account_domain_blocks, :account_id], [:account_domain_blocks, :account_id],
[:account_domain_blocks, :id], [:account_domain_blocks, :id],
[:accounts, :id], [:accounts, :id],
@ -70,17 +67,13 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
[:users, :id], [:users, :id],
[:web_settings, :id], [:web_settings, :id],
[:web_settings, :user_id], [:web_settings, :user_id],
] ].freeze
included_columns << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards)
migration_duration_warning(<<~EXPLANATION) disable_ddl_transaction!
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 def migrate_columns(to_type)
EXPLANATION display_warning
tables = included_columns.map(&:first).uniq
table_sizes = {} table_sizes = {}
# Sort tables by their size # Sort tables by their size
@ -103,6 +96,25 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
end end
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 def up
migrate_columns(:bigint) migrate_columns(:bigint)
end end