From f15a7f20421b94cc5f00f42f94424df9d48247a8 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Wed, 2 Mar 2011 19:01:07 -0300 Subject: [PATCH] Moving serialized data to setting field for some Events --- db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb | 25 +++++++++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb diff --git a/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb b/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb new file mode 100644 index 0000000..99a4506 --- /dev/null +++ b/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb @@ -0,0 +1,25 @@ +class MoveDataSerializedHashToSettingFieldForEvents < ActiveRecord::Migration + def self.up + select_all("SELECT id FROM articles WHERE type = 'Event' AND body LIKE '%:link:%'").each do |data| + article = Event.find(data['id']) + body = '' + begin + body = YAML.load(article.body) + rescue + # do nothing + next + end + if body.kind_of?(Hash) + settings = article.setting.merge(body) + body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description]) + update("UPDATE articles set %s WHERE id = %d" % [body, article.id]) + setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) + update("UPDATE articles set %s WHERE id = %d" % [setting, article.id]) + end + end + end + + def self.down + say "Nothing to undo" + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e0c38b..2951112 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110228174632) do +ActiveRecord::Schema.define(:version => 20110302214607) do create_table "action_tracker", :force => true do |t| t.integer "user_id" -- libgit2 0.21.2