-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
db/migrate/20240123080918_rename_alchemy_attachment_file.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class RenameAlchemyAttachmentFile < ActiveRecord::Migration[7.0] | ||
COLUMNS = %i[ | ||
file_name | ||
file_size | ||
file_uid | ||
] | ||
|
||
def change | ||
COLUMNS.each do |column| | ||
rename_column :alchemy_attachments, column, :"legacy_#{column}" | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
db/migrate/20240123080918_rename_alchemy_picture_image_file.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class RenameAlchemyPictureImageFile < ActiveRecord::Migration[7.0] | ||
COLUMNS = %i[ | ||
image_file_format | ||
image_file_height | ||
image_file_name | ||
image_file_size | ||
image_file_uid | ||
image_file_width | ||
] | ||
|
||
def change | ||
COLUMNS.each do |column| | ||
rename_column :alchemy_pictures, column, :"legacy_#{column}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# frozen_string_literal: true | ||
|
||
require "alchemy/shell" | ||
require "benchmark" | ||
|
||
module Alchemy | ||
class Upgrader::SevenPointOne < Upgrader | ||
extend Alchemy::Shell | ||
DEFAULT_CONTENT_TYPE = "application/octet-stream" | ||
SERVICE_NAME = :alchemy_cms | ||
|
||
# Prevents (down)loading the original file | ||
METADATA = { | ||
identified: true, # Skip identifying file type | ||
analyzed: true, # Skip analyze job | ||
composed: true # Skip checksum check | ||
} | ||
|
||
class << self | ||
def migrate_pictures_to_active_storage | ||
pictures_without_as_attachment = Alchemy::Picture.where.missing(:image_file_attachment) | ||
count = pictures_without_as_attachment.count | ||
if count > 0 | ||
log "Migrating #{count} Dragonfly image file(s) to ActiveStorage." | ||
realtime = Benchmark.realtime do | ||
pictures_without_as_attachment.find_each do |picture| | ||
content_type = Mime::Type.lookup_by_extension(picture.legacy_image_file_format) || DEFAULT_CONTENT_TYPE | ||
Alchemy::Picture.transaction do | ||
blob = Alchemy::Deprecation.silence do | ||
ActiveStorage::Blob.create!( | ||
key: picture.legacy_image_file_uid, | ||
filename: picture.legacy_image_file_name, | ||
byte_size: picture.legacy_image_file_size, | ||
content_type: content_type, | ||
metadata: METADATA.merge( | ||
width: picture.legacy_image_file_width, | ||
height: picture.legacy_image_file_height | ||
), | ||
service_name: SERVICE_NAME | ||
) | ||
end | ||
picture.create_image_file_attachment!( | ||
name: :image_file, | ||
record: picture, | ||
blob: blob | ||
) | ||
end | ||
print "." | ||
end | ||
end | ||
puts "\nDone in #{realtime.round(2)}s!" | ||
else | ||
log "No Dragonfly image files for migration found.", :skip | ||
end | ||
end | ||
|
||
def migrate_attachments_to_active_storage | ||
attachments_without_as_attachment = Alchemy::Attachment.where.missing(:file_attachment) | ||
count = attachments_without_as_attachment.count | ||
if count > 0 | ||
log "Migrating #{count} Dragonfly attachment file(s) to ActiveStorage." | ||
realtime = Benchmark.realtime do | ||
attachments_without_as_attachment.find_each do |attachment| | ||
Alchemy::Attachment.transaction do | ||
blob = Alchemy::Deprecation.silence do | ||
ActiveStorage::Blob.create!( | ||
key: attachment.legacy_file_uid, | ||
filename: attachment.legacy_file_name, | ||
byte_size: attachment.legacy_file_size, | ||
content_type: attachment.file_mime_type.presence || DEFAULT_CONTENT_TYPE, | ||
metadata: METADATA, | ||
service_name: SERVICE_NAME | ||
) | ||
end | ||
attachment.create_file_attachment!( | ||
record: attachment, | ||
name: :file, | ||
blob: blob | ||
) | ||
end | ||
print "." | ||
end | ||
end | ||
puts "\nDone in #{realtime.round(2)}s!" | ||
else | ||
log "No Dragonfly attachment files for migration found.", :skip | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters