From: Simon Brandhof Date: Wed, 17 Aug 2011 14:30:15 +0000 (+0200) Subject: Fix migration of manual measures (again) X-Git-Tag: 2.10~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=48f3f2b0d3ff5b3e88fb763e68549b8435b0cf02;p=sonarqube.git Fix migration of manual measures (again) --- 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 6b651a24e7d..6b2d41db9a4 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 @@ -29,26 +29,25 @@ class MoveAsyncMeasures < ActiveRecord::Migration class ProjectMeasure < ActiveRecord::Base end - class AsyncMeasureSnapshot < ActiveRecord::Base - belongs_to :measure, :foreign_key => 'project_measure_id', :class_name => "ProjectMeasure" - end - def self.up - deprecated_measures=AsyncMeasureSnapshot.find(:all, :include => 'measure', :conditions => 'snapshot_id is not null') + 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 deprecated_measures.each do |dm| - if dm.measure && dm.project_id + if 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, + :metric_id => dm.metric_id, + :value => dm.value, + :text_value => dm.text_value, :created_at => dm.measure_date, :updated_at => dm.measure_date, - :description => dm.measure.description) + :description => dm.description) end end end + + ProjectMeasure.delete_all("snapshot_id is null and measure_date is not null") end end