From: simonbrandhof Date: Tue, 21 Dec 2010 16:24:04 +0000 (+0000) Subject: fix migration on large databases X-Git-Tag: 2.6~265 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=13d356806a18cbcf080aa784765a07fa310b29d8;p=sonarqube.git fix migration on large databases --- diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb index f4253c74b59..2b426cb6520 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb @@ -39,7 +39,9 @@ class DeleteIsoRuleCategories < ActiveRecord::Migration end def self.delete_measures_on_iso_category - puts "If the following step fails, please execute the SQL request 'DELETE FROM PROJECT_MEASURES WHERE RULE_ID IS NULL AND RULES_CATEGORY_ID IS NOT NULL' and restart Sonar." - ProjectMeasure.delete_all('rule_id is null and rules_category_id is not null') + ids=ProjectMeasure.connection.select_values("SELECT ID FROM PROJECT_MEASURES WHERE RULE_ID IS NULL AND RULES_CATEGORY_ID IS NOT NULL") + ids.in_groups_of(900, false) do |group| + ProjectMeasure.delete(group.map{|id| id.to_i}) unless group.empty? + end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/164_delete_measures_on_violations_and_priority.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/164_delete_measures_on_violations_and_priority.rb index b3178dfc8bb..56f2febf0e5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/164_delete_measures_on_violations_and_priority.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/164_delete_measures_on_violations_and_priority.rb @@ -24,8 +24,10 @@ class DeleteMeasuresOnViolationsAndPriority < ActiveRecord::Migration def self.up - puts "If the following step fails, please execute the SQL request 'DELETE FROM PROJECT_MEASURES WHERE RULE_ID IS NULL AND RULE_PRIORITY IS NOT NULL' and restart Sonar." - ProjectMeasure.delete_all('rule_id is null and rule_priority is not null') + ids=ProjectMeasure.connection.select_values("SELECT ID FROM PROJECT_MEASURES WHERE RULE_ID IS NULL AND RULE_PRIORITY IS NOT NULL") + ids.in_groups_of(900, false) do |group| + ProjectMeasure.delete(group.map{|id| id.to_i}) unless group.empty? + end end end