mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Correct checksum of big files stored on AWS S3
This commit is contained in:
17
db/migrate/20220602013938_compute_checksum_for_big_files.rb
Normal file
17
db/migrate/20220602013938_compute_checksum_for_big_files.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# When migrating to Active Storage, we used Amazon's ETag for the blob
|
||||
# checksum. But big files have been uploaded in chunks and then the checksum
|
||||
# differs. We need to recalculate the checksum for large files.
|
||||
class ComputeChecksumForBigFiles < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
blobs_with_incorrect_checksum.find_each do |blob|
|
||||
md5 = Digest::MD5.base64digest(blob.download)
|
||||
blob.update(checksum: md5)
|
||||
end
|
||||
end
|
||||
|
||||
def blobs_with_incorrect_checksum
|
||||
ActiveStorage::Blob.
|
||||
where(service_name: "amazon").
|
||||
where("byte_size >= 20000000")
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_04_10_162955) do
|
||||
ActiveRecord::Schema.define(version: 2022_06_02_013938) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
Reference in New Issue
Block a user