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