Commit b8cb82b68759d581fcb9fc64d5dab44a81341cd5
1 parent
da2e34e6
Exists in
master
and in
1 other branch
Move seed to migration and move existing data
Showing
2 changed files
with
20 additions
and
5 deletions
Show diff stats
db/migrate/20150930132305_move_points_category_to_categorization_tables.rb
0 → 100644
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +class MovePointsCategoryToCategorizationTables < ActiveRecord::Migration | ||
2 | + def up | ||
3 | + Merit::PointRules::AVAILABLE_RULES.each do |name, setting| | ||
4 | + type = GamificationPlugin::PointsType.create(name: name.to_s) | ||
5 | + env = Environment.default | ||
6 | + settings = Noosfero::Plugin::Settings.new(env, GamificationPlugin) | ||
7 | + weight = settings.settings.fetch(:point_rules, {}).fetch(name.to_s, {}).fetch('weight', setting[:default_weight]).to_i | ||
8 | + cat = GamificationPlugin::PointsCategorization.create(point_type_id: type.id, weight: weight) | ||
9 | + Merit::Score.update_all "category = '#{cat.id}'", category: name | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + def down | ||
14 | + GamificationPlugin::PointsCategorization.all.each do |categorization| | ||
15 | + Merit::Score.update_all "category = '#{categorization.point_type.name}'", category: categorization.id.to_s | ||
16 | + categorization.point_type.destroy | ||
17 | + categorization.destroy | ||
18 | + end | ||
19 | + end | ||
20 | +end |