2019-08-14 09:48:44 +00:00
|
|
|
require 'uri'
|
|
|
|
class CreateExtensionForFile < ActiveRecord::Migration[5.0]
|
|
|
|
def change
|
|
|
|
add_column :attachments, :extension, :string, default: nil
|
|
|
|
Attachment.find_each do |attachment|
|
2019-10-20 08:47:26 +00:00
|
|
|
if attachment.external_url && (attachment.file_type != fallback)
|
|
|
|
attachment.extension = begin
|
|
|
|
Pathname.new(URI(attachment.external_url).path).extname
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
attachment.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|