Commit b8cb82b68759d581fcb9fc64d5dab44a81341cd5

Authored by Hugo Melo
1 parent da2e34e6

Move seed to migration and move existing data

db/migrate/20150930132305_move_points_category_to_categorization_tables.rb 0 → 100644
... ... @@ -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
... ...
db/seeds.rb
... ... @@ -1,5 +0,0 @@
1   -unless GamificationPlugin::PointsType.count
2   - Merit::PointRules::AVAILABLE_RULES.each do |name , setting|
3   - GamificationPlugin::PointsType.create! name: name.to_s, description: setting[:description]
4   - end
5   -end