Chatwoot/db/migrate/20170503162643_create_extension_for_file.rb
2019-10-20 14:17:26 +05:30

16 lines
565 B
Ruby

require 'uri'
class CreateExtensionForFile < ActiveRecord::Migration[5.0]
def change
add_column :attachments, :extension, :string, default: nil
Attachment.find_each do |attachment|
if attachment.external_url && (attachment.file_type != fallback)
attachment.extension = begin
Pathname.new(URI(attachment.external_url).path).extname
rescue StandardError
nil
end
attachment.save!
end
end
end
end