diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-17 16:30:15 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-17 16:30:15 +0200 |
commit | 48f3f2b0d3ff5b3e88fb763e68549b8435b0cf02 (patch) | |
tree | b02781c75131db4da2375b508da7e31d76b45f9d /sonar-server | |
parent | 9ca86cd73f8807401910cf8610b7b37bfb528b10 (diff) | |
download | sonarqube-48f3f2b0d3ff5b3e88fb763e68549b8435b0cf02.tar.gz sonarqube-48f3f2b0d3ff5b3e88fb763e68549b8435b0cf02.zip |
Fix migration of manual measures (again)
Diffstat (limited to 'sonar-server')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/db/migrate/212_move_async_measures.rb | 19 |
1 files changed, 9 insertions, 10 deletions
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 |