]> source.dussan.org Git - sonarqube.git/commitdiff
Fix migration of manual measures
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 9 Aug 2011 08:38:24 +0000 (10:38 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 9 Aug 2011 08:38:24 +0000 (10:38 +0200)
sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb

index d9caab90f1b09a42caeaa236dd4fdd07ad16d2a2..6b651a24e7d9e9b2a3f975c0d57566831e451535 100644 (file)
@@ -34,19 +34,19 @@ class MoveAsyncMeasures < ActiveRecord::Migration
   end
 
   def self.up
-    deprecated_measures=AsyncMeasureSnapshot.find(:all, :include => 'measure')
-    
+    deprecated_measures=AsyncMeasureSnapshot.find(:all, :include => 'measure', :conditions => 'snapshot_id is not null')
     say_with_time "Moving #{deprecated_measures.size} measures" do
       deprecated_measures.each do |dm|
-        ManualMeasure.create(
-            :resource_id => dm.project_id,
-            :metric_id => dm.measure.metric_id,
-            :value => dm.measure.value,
-            :text_value => dm.measure.text_value,
-            :created_at => dm.measure_date,
-            :updated_at => dm.measure_date,
-            :description => dm.measure.description
-        )
+        if dm.measure && dm.project_id
+          ManualMeasure.create(
+              :resource_id => dm.project_id,
+              :metric_id => dm.measure.metric_id,
+              :value => dm.measure.value,
+              :text_value => dm.measure.text_value,
+              :created_at => dm.measure_date,
+              :updated_at => dm.measure_date,
+              :description => dm.measure.description)
+        end
       end
     end
   end