diff --git a/db/migrate/20241223161545_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20241223161545_add_service_name_to_active_storage_blobs.active_storage.rb index a15c6ce..0267f12 100644 --- a/db/migrate/20241223161545_add_service_name_to_active_storage_blobs.active_storage.rb +++ b/db/migrate/20241223161545_add_service_name_to_active_storage_blobs.active_storage.rb @@ -6,7 +6,7 @@ def up unless column_exists?(:active_storage_blobs, :service_name) add_column :active_storage_blobs, :service_name, :string - if configured_service = ActiveStorage::Blob.service.name + if (configured_service = ActiveStorage::Blob.service.name) ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) end diff --git a/db/migrate/20241223161546_create_active_storage_variant_records.active_storage.rb b/db/migrate/20241223161546_create_active_storage_variant_records.active_storage.rb index 94ac83a..95fd27f 100644 --- a/db/migrate/20241223161546_create_active_storage_variant_records.active_storage.rb +++ b/db/migrate/20241223161546_create_active_storage_variant_records.active_storage.rb @@ -8,20 +8,21 @@ def change t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type t.string :variation_digest, null: false - t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.index %i[blob_id variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true t.foreign_key :active_storage_blobs, column: :blob_id end end private - def primary_key_type - config = Rails.configuration.generators - config.options[config.orm][:primary_key_type] || :primary_key - end - def blobs_primary_key_type - pkey_name = connection.primary_key(:active_storage_blobs) - pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } - pkey_column.bigint? ? :bigint : pkey_column.type - end + def primary_key_type + config = Rails.configuration.generators + config.options[config.orm][:primary_key_type] || :primary_key + end + + def blobs_primary_key_type + pkey_name = connection.primary_key(:active_storage_blobs) + pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } + pkey_column.bigint? ? :bigint : pkey_column.type + end end