Chatwoot/db/migrate/20170503162643_create_extension_for_file.rb
Pranav Raj Sreepuram 2a34255e0b Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com>
Co-authored-by: Manoj <manojmj92@gmail.com>
Co-authored-by: Nithin <webofnithin@gmail.com>
2019-08-14 15:18:44 +05:30

12 lines
412 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 and attachment.file_type != fallback
attachment.extension = Pathname.new(URI(attachment.external_url).path).extname rescue nil
attachment.save!
end
end
end
end