From: Simon Brandhof Date: Thu, 13 Jun 2013 21:53:05 +0000 (+0200) Subject: SONAR-4305 purge unprocessed violations before migrating to issues X-Git-Tag: 3.7~485 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c4587b97a8c4c0f4d106d8a8aec91a5d14f18601;p=sonarqube.git SONAR-4305 purge unprocessed violations before migrating to issues --- diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index aaef7a8f832..18020cb76a1 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -150,6 +150,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('361'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('362'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('363'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('370'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('379'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('380'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('381'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('382'); diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb index a6c787ced7a..1235fe1603d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb @@ -39,7 +39,7 @@ class DeleteCheckstyleTranslations < ActiveRecord::Migration def self.delete_rule(rule_key) rule=Rule.find(:first, :conditions => {:plugin_name => 'checkstyle', :plugin_rule_key => rule_key}) if rule - say_with_time "Deleting Checkstyle rule #{rule_key}..." do + say_with_time "Delete Checkstyle rule #{rule_key}..." do rule_id=rule.id ActiveRule.destroy_all(["rule_id=?", rule_id]) rule.destroy diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb index c9991266c86..986e6a70fe7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb @@ -42,7 +42,7 @@ class DeleteUnvalidProjectSnapshots < ActiveRecord::Migration def self.delete_snapshots(snapshots) if snapshots.size>0 - say_with_time "Deleting #{snapshots.size} orphan snapshots..." do + say_with_time "Delete #{snapshots.size} orphan snapshots..." do sids=snapshots.map{|s| s.id} page_size=100 page_count=(sids.size/page_size) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb index 3fef397db24..ccf91011409 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb @@ -35,7 +35,7 @@ class MoveAsyncMeasures < ActiveRecord::Migration deprecated_measures=ProjectMeasure.find_by_sql("select p1.* from project_measures p1 where p1.snapshot_id is null and p1.measure_date is not null and not exists(select id from project_measures p2 where p2.project_id=p1.project_id and p2.metric_id=p1.metric_id and p2.measure_date is not null and p2.measure_date>p1.measure_date)") - say_with_time "Moving #{deprecated_measures.size} measures" do + say_with_time "Move #{deprecated_measures.size} measures" do deprecated_measures.each do |dm| if dm.project_id ManualMeasure.create( diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/287_index_projects.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/287_index_projects.rb index 7eff6a11ef0..b972594686a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/287_index_projects.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/287_index_projects.rb @@ -35,7 +35,7 @@ class IndexProjects < ActiveRecord::Migration projects = Project.find(:all, :select => 'id', :conditions => {:enabled => true, :scope => 'PRJ'}) - say_with_time "Indexing #{projects.size} projects" do + say_with_time "Index #{projects.size} projects" do projects.each do |project| Java::OrgSonarServerUi::JRubyFacade.getInstance().indexResource(project.id) end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/331_remove_projects_profile_id.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/331_remove_projects_profile_id.rb index f294265eb51..32f94026772 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/331_remove_projects_profile_id.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/331_remove_projects_profile_id.rb @@ -36,7 +36,7 @@ class RemoveProjectsProfileId < ActiveRecord::Migration def self.up projects=Project.find(:all, :conditions => ['profile_id is not null and copy_resource_id is null']) - say_with_time "Processing #{projects.size} projects..." do + say_with_time "Process #{projects.size} projects..." do projects.each do |project| profile = Profile.find(:first, :conditions => ['id=?', project.profile_id]) if profile diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_existing_measure_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_existing_measure_filters.rb index 583131c6bb0..ca2eccc2044 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_existing_measure_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_existing_measure_filters.rb @@ -43,7 +43,7 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration def self.up old_filters = OldFilter.find(:all) - say_with_time "Moving #{old_filters.size} measure filters" do + say_with_time "Move #{old_filters.size} measure filters" do old_filters.each do |old_filter| move(old_filter) end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/361_move_filter_widgets.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/361_move_filter_widgets.rb index 1733bc1aa9b..0c559eee77d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/361_move_filter_widgets.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/361_move_filter_widgets.rb @@ -41,7 +41,7 @@ class MoveFilterWidgets < ActiveRecord::Migration def self.up widgets = Widget.find(:all, :conditions => ["widget_key='filter'"]) - say_with_time "Updading #{widgets.size} widgets" do + say_with_time "Update #{widgets.size} widgets" do widgets.each do |widget| dashboard = Dashboard.find_by_id(widget.dashboard_id) widget_property = WidgetProperty.find(:first, :conditions => {:widget_id => widget.id, :kee => 'filter'}) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/379_purge_violations.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/379_purge_violations.rb new file mode 100644 index 00000000000..6038fe53159 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/379_purge_violations.rb @@ -0,0 +1,39 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# Sonar 3.6 +# +class PurgeViolations < ActiveRecord::Migration + + class RuleFailure < ActiveRecord::Base + end + + def self.up + violation_ids = ActiveRecord::Base.connection.select_rows('select rf.id from rule_failures rf inner join snapshots s on rf.snapshot_id=s.id where s.islast=' + ActiveRecord::Base.connection.quoted_false) + say_with_time "Purge #{violation_ids.size} violations" do + violation_ids.each_slice(999) do |ids| + RuleFailure.delete(ids.flatten) if ids.size>0 + end + end + end + +end + diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/400_delete_review_duplications.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/400_delete_review_duplications.rb index d6b39a8469b..da052697b7b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/400_delete_review_duplications.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/400_delete_review_duplications.rb @@ -29,7 +29,7 @@ class DeleteReviewDuplications < ActiveRecord::Migration def self.up duplicated_ids = ActiveRecord::Base.connection.select_rows('select rule_failure_permanent_id from reviews group by rule_failure_permanent_id having count(*) > 1') - say_with_time "Removing #{duplicated_ids.size} duplicated reviews" do + say_with_time "Remove #{duplicated_ids.size} duplicated reviews" do duplicated_ids.each do |id| reviews = Review.find(:all, :conditions => {:rule_failure_permanent_id => id}) # delete all reviews except the last one diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb index e13ca9b25b0..f3b618c5f26 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/401_migrate_violations_to_issues.rb @@ -48,7 +48,7 @@ class MigrateViolationsToIssues < ActiveRecord::Migration one_year_ago = Time.now.years_ago(1) - say_with_time "Converting #{violation_ids.size} violations to issues" do + say_with_time "Convert #{violation_ids.size} violations to issues" do logins_by_id = User.all.inject({}) do |result, user| result[user.id]=user.login result @@ -151,7 +151,7 @@ class MigrateViolationsToIssues < ActiveRecord::Migration from rule_failures rf inner join snapshots s on s.id=rf.snapshot_id left join reviews rev on rev.rule_failure_permanent_id=rf.permanent_id - where rf.id in (#{ids.join(',')})" + where rf.id in (#{ids.flatten.join(',')})" end def self.new_key