Commit 130dc63094a703909ed1147d9895d3a26d098879
1 parent
907bb8d2
Exists in
master
and in
28 other branches
Use SQL directly to upgrade needed data.
(ActionItem1258)
Showing
1 changed file
with
5 additions
and
7 deletions
Show diff stats
db/migrate/074_move_title_to_name_from_blogs.rb
| 1 | class MoveTitleToNameFromBlogs < ActiveRecord::Migration | 1 | class MoveTitleToNameFromBlogs < ActiveRecord::Migration |
| 2 | def self.up | 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 | end | 7 | end |
| 7 | end | 8 | end |
| 8 | 9 | ||
| 9 | def self.down | 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 | end | 12 | end |
| 15 | end | 13 | end |