Commit 130dc63094a703909ed1147d9895d3a26d098879

Authored by Antonio Terceiro
1 parent 907bb8d2

Use SQL directly to upgrade needed data.

(ActionItem1258)
db/migrate/074_move_title_to_name_from_blogs.rb
1 1 class MoveTitleToNameFromBlogs < ActiveRecord::Migration
2 2 def self.up
3   - Blog.find(:all).each do |blog|
4   - blog.name = blog.title
5   - blog.save
  3 + select_all("select id, setting from articles where type = 'Blog' and name != 'Blog'").each do |blog|
  4 + title = YAML.load(blog['setting'])[:title]
  5 + assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:name => title)
  6 + update("update articles set %s where id = %d" % [assignments, blog['id']] )
6 7 end
7 8 end
8 9  
9 10 def self.down
10   - Blog.find(:all).each do |blog|
11   - blog.title = blog.name
12   - blog.save
13   - end
  11 + say("Nothing to undo (cannot recover the data)")
14 12 end
15 13 end
... ...