cirandas.net

ref: master

db/migrate/20140221142304_move_title_virtual_field_to_name_in_uploaded_file.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class MoveTitleVirtualFieldToNameInUploadedFile < ActiveRecord::Migration
  def self.up
    UploadedFile.find_each do |uploaded_file|
      uploaded_file.name = uploaded_file.setting.delete(:title)
      UploadedFile.where(id: uploaded_file.id).update_all setting: uploaded_file.setting.to_yaml, name: uploaded_file.name

    end
  end

  def self.down
    say "this migration can't be reverted"
  end
end