Commit 1581240eb791cf70901389ed6ac271262f9cd24e
1 parent
a4abbe84
Exists in
master
and in
1 other branch
Add badge threshold migration
Showing
1 changed file
with
23 additions
and
0 deletions
Show diff stats
db/migrate/20151003000212_move_badge_threshold_to_action_key.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +class MoveBadgeThresholdToActionKey < ActiveRecord::Migration | ||
2 | + def up | ||
3 | + GamificationPlugin::Badge.all.each do |badge| | ||
4 | + next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? | ||
5 | + Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| | ||
6 | + setting = settings.first | ||
7 | + badge.custom_fields[setting[:action]] = {threshold: badge.custom_fields[:threshold]} unless badge.custom_fields[:threshold].nil? | ||
8 | + badge.save | ||
9 | + end | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + def down | ||
14 | + GamificationPlugin::Badge.all.each do |badge| | ||
15 | + next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? | ||
16 | + Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| | ||
17 | + setting = settings.first | ||
18 | + badge.custom_fields[:threshold] = badge.custom_fields[setting[:action]][:threshold] unless badge.custom_fields[setting[:action]][:threshold].nil? | ||
19 | + badge.save | ||
20 | + end | ||
21 | + end | ||
22 | + end | ||
23 | +end |