From 4b4085303b3d4c970bc950206d1da0cd5cf97b1f Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 5 Jan 2011 09:14:17 +0000 Subject: improve db migration to avoid deleting special snapshots (like pacbase projects) --- .../db/migrate/170_delete_unvalid_project_snapshots.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'sonar-server') diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb index 623f1c8087f..e14e0dfa506 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb @@ -24,17 +24,14 @@ class DeleteUnvalidProjectSnapshots < ActiveRecord::Migration def self.up - metric=Metric.find(:first, :conditions => ['name=?','lines']) - if metric - snapshots=select_snapshots_without_measures(metric) - delete_snapshots(snapshots) - end + snapshots=select_snapshots_without_measures + delete_snapshots(snapshots) end - def self.select_snapshots_without_measures(metric) + def self.select_snapshots_without_measures snapshots=nil say_with_time "Select project snapshots without measures..." do - snapshots=Snapshot.find_by_sql ["SELECT s.id FROM snapshots s WHERE s.scope='PRJ' and s.qualifier IN ('TRK', 'BRC') AND status='P' AND islast=? AND NOT EXISTS (select m.id from project_measures m WHERE m.snapshot_id=s.id AND m.metric_id=?)", false, metric.id] + snapshots=Snapshot.find_by_sql ["SELECT s.id FROM snapshots s WHERE s.scope='PRJ' and s.qualifier IN ('TRK', 'BRC') AND status='P' AND islast=? AND NOT EXISTS (select m.id from project_measures m WHERE m.snapshot_id=s.id)", false] end snapshots end -- cgit v1.2.3