From 5125e5a82739f0cf9351febe65745495ff3f92cc Mon Sep 17 00:00:00 2001 From: Hugo Melo Date: Wed, 7 Oct 2015 10:57:05 -0300 Subject: [PATCH] Fix badge migration --- db/migrate/20151003000212_move_badge_threshold_to_action_key.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb b/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb index 8f3dedd..24d3736 100644 --- a/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb +++ b/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb @@ -1,9 +1,11 @@ class MoveBadgeThresholdToActionKey < ActiveRecord::Migration def up + change_table :gamification_plugin_badges do |t| + t.change :custom_fields, :text + end GamificationPlugin::Badge.all.each do |badge| next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? - Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| - setting = settings.first + Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].each do |setting| badge.custom_fields[setting[:action]] = {threshold: badge.custom_fields[:threshold]} unless badge.custom_fields[:threshold].nil? badge.save end @@ -13,11 +15,12 @@ class MoveBadgeThresholdToActionKey < ActiveRecord::Migration def down GamificationPlugin::Badge.all.each do |badge| next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? - Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| - setting = settings.first - badge.custom_fields[:threshold] = badge.custom_fields[setting[:action]][:threshold] unless badge.custom_fields[setting[:action]][:threshold].nil? - badge.save - end + setting = Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].first + badge.custom_fields = {threshold: badge.custom_fields.fetch(setting[:action], {}).fetch(:threshold, "")} + badge.save + end + change_table :gamification_plugin_badges do |t| + t.change :custom_fields, :string end end end -- libgit2 0.21.2