Commit f15a7f20421b94cc5f00f42f94424df9d48247a8
Committed by
Daniela Feitosa
1 parent
02c67027
Exists in
master
and in
22 other branches
Moving serialized data to setting field for some Events
(ActionItem1914)
Showing
2 changed files
with
26 additions
and
1 deletions
Show diff stats
db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +class MoveDataSerializedHashToSettingFieldForEvents < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + select_all("SELECT id FROM articles WHERE type = 'Event' AND body LIKE '%:link:%'").each do |data| | ||
4 | + article = Event.find(data['id']) | ||
5 | + body = '' | ||
6 | + begin | ||
7 | + body = YAML.load(article.body) | ||
8 | + rescue | ||
9 | + # do nothing | ||
10 | + next | ||
11 | + end | ||
12 | + if body.kind_of?(Hash) | ||
13 | + settings = article.setting.merge(body) | ||
14 | + body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description]) | ||
15 | + update("UPDATE articles set %s WHERE id = %d" % [body, article.id]) | ||
16 | + setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) | ||
17 | + update("UPDATE articles set %s WHERE id = %d" % [setting, article.id]) | ||
18 | + end | ||
19 | + end | ||
20 | + end | ||
21 | + | ||
22 | + def self.down | ||
23 | + say "Nothing to undo" | ||
24 | + end | ||
25 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 20110228174632) do | 12 | +ActiveRecord::Schema.define(:version => 20110302214607) do |
13 | 13 | ||
14 | create_table "action_tracker", :force => true do |t| | 14 | create_table "action_tracker", :force => true do |t| |
15 | t.integer "user_id" | 15 | t.integer "user_id" |