Remove no-longer-needed migration scripts
This commit is contained in:
parent
2fef9c7043
commit
a26b5eaa23
4 changed files with 0 additions and 112 deletions
|
|
@ -1,34 +0,0 @@
|
|||
namespace :debshots do
|
||||
desc "Convert images from Paperclip schema to ActiveStorage schema"
|
||||
|
||||
task paperclip_to_activestorage: :environment do
|
||||
klass = Screenshot
|
||||
attachment = 'image'
|
||||
name_field = :"#{attachment}_file_name"
|
||||
|
||||
klass.where.not(name_field => nil).find_each do |instance|
|
||||
# This step helps us catch any attachments we might have uploaded that
|
||||
# don't have an explicit file extension in the filename
|
||||
|
||||
puts "----------"
|
||||
filename = instance.send("#{attachment}_file_name")
|
||||
puts filename
|
||||
|
||||
next if filename.blank?
|
||||
|
||||
id = instance.id
|
||||
id_partition = ("%09d".freeze % id).scan(/\d{3}/).join("/".freeze)
|
||||
path = "storage/#{klass.table_name}/#{attachment.pluralize}/#{id_partition}/original/#{filename}"
|
||||
puts path
|
||||
|
||||
#url = "https://nyc3.digitaloceanspaces.com/gorails/#{klass.table_name}/#{attachment.pluralize}/#{id_partition}/original/#{filename}"
|
||||
|
||||
instance.send(attachment.to_sym).attach(
|
||||
# io: open(url),
|
||||
io: File.open(path),
|
||||
filename: instance.send(name_field),
|
||||
content_type: instance.send(:"#{attachment}_content_type")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
namespace :debshots do
|
||||
desc "Convert images from Paperclip (deprecated) to Shrine"
|
||||
|
||||
task paperclip_to_shrine: :environment do
|
||||
|
||||
Screenshot.find_each do |screenshot|
|
||||
puts "Screenshot… #{screenshot.id}"
|
||||
path = screenshot.image.path
|
||||
puts "Image path… #{path}"
|
||||
|
||||
# Skip run if there is a Shrine attachment already (idempotency)
|
||||
next if screenshot.simage
|
||||
|
||||
# Upload file as Shrine
|
||||
screenshot.simage = File.open(path)
|
||||
|
||||
puts "Creating derivatives…"
|
||||
screenshot.simage_derivatives!
|
||||
|
||||
screenshot.save!
|
||||
puts "------------"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
namespace :debshots do
|
||||
desc "Preprocess image variants to speed up loading times"
|
||||
|
||||
task preprocess_image_variants: :environment do
|
||||
|
||||
ss = Screenshot.all.each do |ss|
|
||||
return unless ss.image.attached?
|
||||
|
||||
Rails.logger.info "Processed variants for #{ss.id} of #{ss.package.name}"
|
||||
ss.medium_image
|
||||
ss.large_image_watermarked
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
namespace :debshots do
|
||||
desc "Convert images from the original screenshots directory tree to paperclip-styled images"
|
||||
|
||||
task :screenshots_to_paperclip => :environment do
|
||||
Rails.logger = Logger.new(STDOUT)
|
||||
# Rails.logger.level = Logger::INFO
|
||||
Rails.logger.level = Logger::DEBUG
|
||||
|
||||
base_path = Rails.root.join('public')
|
||||
|
||||
Rails.logger.info "Iterating over screenshots"
|
||||
Screenshot.all.each do |screenshot|
|
||||
path = File.join(base_path, screenshot.image_url(:large))
|
||||
Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
|
||||
|
||||
# Check that the file actually exists
|
||||
unless File.file? path
|
||||
Rails.logger.error "Screenshots not found at #{path}. Skipping."
|
||||
next
|
||||
end
|
||||
|
||||
# Has the screenshot been migrated already?
|
||||
if screenshot.image.exists?
|
||||
Rails.logger.info "Screenshot already migrated. Skipping."
|
||||
next
|
||||
end
|
||||
|
||||
File.open(path, 'rb') do |image_file|
|
||||
screenshot.image = image_file
|
||||
Rails.logger.debug "Adding image file: #{image_file}"
|
||||
unless screenshot.valid?
|
||||
Rails.logger.error "Adding image file failed. Errors: #{screenshot.errors[:image]}"
|
||||
end
|
||||
screenshot.save
|
||||
Rails.logger.debug "Screenshot object saved"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue