Migrate paperclip _file_size columns to bigint (#29263)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Matt Jankowski 2024-05-06 11:05:12 -04:00 committed by GitHub
parent 05126d106f
commit b152f936c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 9 deletions

View file

@ -0,0 +1,42 @@
# frozen_string_literal: true
require_relative '../../lib/mastodon/migration_helpers'
class ConvertFileSizeColumnsToBigInt < ActiveRecord::Migration[7.1]
include Mastodon::MigrationHelpers
TABLE_COLUMN_MAPPING = [
[:accounts, :avatar_file_size],
[:accounts, :header_file_size],
[:custom_emojis, :image_file_size],
[:imports, :data_file_size],
[:media_attachments, :file_file_size],
[:media_attachments, :thumbnail_file_size],
[:preview_cards, :image_file_size],
[:site_uploads, :file_file_size],
].freeze
disable_ddl_transaction!
def migrate_columns(to_type)
TABLE_COLUMN_MAPPING.each do |column_parts|
table, column = column_parts
# Skip this if we're resuming and already did this one.
next if column_for(table, column).sql_type == to_type.to_s
safety_assured do
change_column_type_concurrently table, column, to_type
cleanup_concurrent_column_type_change table, column
end
end
end
def up
migrate_columns(:bigint)
end
def down
migrate_columns(:integer)
end
end