From d7c13bf44380f2306e8f7266f9bf0ad593f55612 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 10 May 2024 07:07:50 +0900 Subject: [PATCH] Fix test --- app/models/account.rb | 4 +- app/models/custom_emoji.rb | 2 +- app/models/import.rb | 2 +- app/models/media_attachment.rb | 4 +- app/models/preview_card.rb | 2 +- app/models/site_upload.rb | 2 +- ...evert_media_file_size_column_to_big_int.rb | 42 +++++++++++++++++++ db/schema.rb | 18 ++++---- 8 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20240509220635_revert_media_file_size_column_to_big_int.rb diff --git a/app/models/account.rb b/app/models/account.rb index dd85767bc4e3a1..865624181a7e9e 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -53,8 +53,8 @@ # indexable :boolean default(FALSE), not null # master_settings :jsonb # remote_pending :boolean default(FALSE), not null -# avatar_file_size :bigint(8) -# header_file_size :bigint(8) +# avatar_file_size :integer +# header_file_size :integer # class Account < ApplicationRecord diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index bef804106fdef6..a043c3ae1043a5 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -23,7 +23,7 @@ # aliases :jsonb # is_sensitive :boolean default(FALSE), not null # license :string -# image_file_size :bigint(8) +# image_file_size :integer # class CustomEmoji < ApplicationRecord diff --git a/app/models/import.rb b/app/models/import.rb index 281b25a36e9d5f..6b261f8d00a74c 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -14,7 +14,7 @@ # data_updated_at :datetime # account_id :bigint(8) not null # overwrite :boolean default(FALSE), not null -# data_file_size :bigint(8) +# data_file_size :integer # # NOTE: This is a deprecated model, only kept to not break ongoing imports diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 668349389f279d..4bd7c643d270a3 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -25,8 +25,8 @@ # thumbnail_content_type :string # thumbnail_updated_at :datetime # thumbnail_remote_url :string -# file_file_size :bigint(8) -# thumbnail_file_size :bigint(8) +# file_file_size :integer +# thumbnail_file_size :integer # class MediaAttachment < ApplicationRecord diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb index 56b72b5e6fe87f..65a55bbd082f7e 100644 --- a/app/models/preview_card.rb +++ b/app/models/preview_card.rb @@ -31,7 +31,7 @@ # link_type :integer # published_at :datetime # image_description :string default(""), not null -# image_file_size :bigint(8) +# image_file_size :integer # class PreviewCard < ApplicationRecord diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb index 2f5651de0125d2..93e7e7f3f1f5e2 100644 --- a/app/models/site_upload.rb +++ b/app/models/site_upload.rb @@ -13,7 +13,7 @@ # created_at :datetime not null # updated_at :datetime not null # blurhash :string -# file_file_size :bigint(8) +# file_file_size :integer # class SiteUpload < ApplicationRecord diff --git a/db/migrate/20240509220635_revert_media_file_size_column_to_big_int.rb b/db/migrate/20240509220635_revert_media_file_size_column_to_big_int.rb new file mode 100644 index 00000000000000..eb75e56924daaa --- /dev/null +++ b/db/migrate/20240509220635_revert_media_file_size_column_to_big_int.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require_relative '../../lib/mastodon/migration_helpers' + +class RevertMediaFileSizeColumnToBigInt < 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(:integer) + end + + def down + migrate_columns(:integer) + end +end diff --git a/db/schema.rb b/db/schema.rb index b5d2f9c977cc98..be0b0606513e6c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_04_26_233435) do +ActiveRecord::Schema[7.1].define(version: 2024_05_09_220635) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -204,8 +204,8 @@ t.boolean "indexable", default: false, null: false t.jsonb "master_settings" t.boolean "remote_pending", default: false, null: false - t.bigint "avatar_file_size" - t.bigint "header_file_size" + t.integer "avatar_file_size" + t.integer "header_file_size" t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true t.index ["domain", "id"], name: "index_accounts_on_domain_and_id" @@ -505,7 +505,7 @@ t.jsonb "aliases" t.boolean "is_sensitive", default: false, null: false t.string "license" - t.bigint "image_file_size" + t.integer "image_file_size" t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true end @@ -735,7 +735,7 @@ t.datetime "data_updated_at", precision: nil t.bigint "account_id", null: false t.boolean "overwrite", default: false, null: false - t.bigint "data_file_size" + t.integer "data_file_size" end create_table "instance_infos", force: :cascade do |t| @@ -846,8 +846,8 @@ t.string "thumbnail_content_type" t.datetime "thumbnail_updated_at", precision: nil t.string "thumbnail_remote_url" - t.bigint "file_file_size" - t.bigint "thumbnail_file_size" + t.integer "file_file_size" + t.integer "thumbnail_file_size" t.index ["account_id", "status_id"], name: "index_media_attachments_on_account_id_and_status_id", order: { status_id: :desc } t.index ["id"], name: "index_media_attachments_vacuum", where: "((file_file_name IS NOT NULL) AND ((remote_url)::text <> ''::text))" t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id", where: "(scheduled_status_id IS NOT NULL)" @@ -1174,7 +1174,7 @@ t.integer "link_type" t.datetime "published_at" t.string "image_description", default: "", null: false - t.bigint "image_file_size" + t.integer "image_file_size" t.index ["id"], name: "index_preview_cards_vacuum", where: "((image_file_name IS NOT NULL) AND ((image_file_name)::text <> ''::text))" t.index ["url"], name: "index_preview_cards_on_url", unique: true end @@ -1317,7 +1317,7 @@ t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.string "blurhash" - t.bigint "file_file_size" + t.integer "file_file_size" t.index ["var"], name: "index_site_uploads_on_var", unique: true end