cirandas.net

ref: master

db/migrate/074_move_title_to_name_from_blogs.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class MoveTitleToNameFromBlogs < ActiveRecord::Migration
  def self.up
    select_all("select id, setting from articles where type = 'Blog' and name != 'Blog'").each do |blog|
      title = YAML.load(blog['setting'])[:title]
      assignments = ApplicationRecord.sanitize_sql_for_assignment(:name => title)
      update("update articles set %s where id = %d" % [assignments, blog['id']] )
    end
  end

  def self.down
    say("Nothing to undo (cannot recover the data)")
  end
end