diff --git a/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb b/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb new file mode 100644 index 0000000..df0c93b --- /dev/null +++ b/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb @@ -0,0 +1,36 @@ +class RenameImagesPathOnTrackedActions < ActiveRecord::Migration + + def self.up + select_all("SELECT id, verb, params FROM action_tracker WHERE verb IN ('new_friendship', 'join_community', 'leave_community')").each do |tracker| + if tracker['verb'] == 'new_friendship' + param_name = 'friend_profile_custom_icon' + else + param_name = 'resource_profile_custom_icon' + end + + params = YAML.load(tracker['params']) + paths = [] + params[param_name].each do |image_path| + paths << self.rename_path(image_path) unless image_path.nil? + end + params[param_name] = paths + + execute(ActiveRecord::Base.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']])) + end + end + + def self.down + say('Nothing to undo') + end + + class << self + def rename_path(old_path) + if old_path =~ /^\/images\/0/ + old_path.gsub(/^\/images\//, "/image_uploads/") + else + old_path + end + end + end + +end diff --git a/db/schema.rb b/db/schema.rb index e28c978..2b0cf5a 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 => 20110202141024) do +ActiveRecord::Schema.define(:version => 20110203160153) do create_table "action_tracker", :force => true do |t| t.integer "user_id" -- libgit2 0.21.2