]> source.dussan.org Git - sonarqube.git/commitdiff
fix migration on large databases
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 21 Dec 2010 16:24:04 +0000 (16:24 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 21 Dec 2010 16:24:04 +0000 (16:24 +0000)
sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/164_delete_measures_on_violations_and_priority.rb

index f4253c74b5904efd3503b2035e0462cd954a6d46..2b426cb652017f5ab5e46e395aa1e0292c2b9daa 100644 (file)
@@ -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
index b3178dfc8bb9cf6d385c6586ce5d83aecdeedb9a..56f2febf0e5f2ac85cc3e0cf50b4e118bf45d027 100644 (file)
 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