You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231_refactor_rule_measures.rb 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # SonarQube, open source software quality management tool.
  3. # Copyright (C) 2008-2014 SonarSource
  4. # mailto:contact AT sonarsource DOT com
  5. #
  6. # SonarQube is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 3 of the License, or (at your option) any later version.
  10. #
  11. # SonarQube is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. #
  21. # Sonar 2.13
  22. # http://jira.sonarsource.com/browse/SONAR-1974
  23. #
  24. class RefactorRuleMeasures < ActiveRecord::Migration
  25. class ProjectMeasure < ActiveRecord::Base
  26. end
  27. class Metric < ActiveRecord::Base
  28. end
  29. def self.up
  30. Metric.reset_column_information
  31. ProjectMeasure.reset_column_information
  32. replace('violations', 0, 'info_violations')
  33. replace('violations', 1, 'minor_violations')
  34. replace('violations', 2, 'major_violations')
  35. replace('violations', 3, 'critical_violations')
  36. replace('violations', 4, 'blocker_violations')
  37. replace('new_violations', 0, 'new_info_violations')
  38. replace('new_violations', 1, 'new_minor_violations')
  39. replace('new_violations', 2, 'new_major_violations')
  40. replace('new_violations', 3, 'new_critical_violations')
  41. replace('new_violations', 4, 'new_blocker_violations')
  42. end
  43. private
  44. def self.replace(from_metric_key, from_severity, to_metric_key)
  45. from_metric = Metric.find_by_name(from_metric_key)
  46. to_metric = Metric.find_by_name(to_metric_key)
  47. if from_metric && to_metric
  48. say_with_time("Update metric #{to_metric_key}") do
  49. ProjectMeasure.update_all("metric_id=#{to_metric.id}", "metric_id=#{from_metric.id} AND rule_id IS NOT NULL AND rule_priority=#{from_severity}")
  50. end
  51. end
  52. end
  53. end