Skip to content

Commit

Permalink
Move length value mapping to constant in ids to bigints migration (ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and skerit committed Feb 27, 2024
1 parent b309b13 commit 61b5b01
Showing 1 changed file with 82 additions and 70 deletions.
152 changes: 82 additions & 70 deletions db/migrate/20170918125918_ids_to_bigints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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.
display_warning

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
Expand All @@ -103,6 +96,25 @@ def migrate_columns(to_type)
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
Expand Down

0 comments on commit 61b5b01

Please sign in to comment.