Move length value mapping to constant in ids to bigints migration (#29048)
This commit is contained in:
parent
4cf07ed78c
commit
dedefdc303
1 changed files with 82 additions and 70 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue