]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3929 Database upgrade fails
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 5 Nov 2012 13:46:01 +0000 (14:46 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 5 Nov 2012 13:46:37 +0000 (14:46 +0100)
sonar-server/src/main/webapp/WEB-INF/db/migrate/331_remove_projects_profile_id.rb

index 68fc65062e476e7d3a3cc03db6b536f70eb5c3f9..abe99ac17c9a83bc0affee52d97b6877847bf1c9 100644 (file)
@@ -28,16 +28,21 @@ class RemoveProjectsProfileId < ActiveRecord::Migration
   end
 
   class Project < ActiveRecord::Base
-    belongs_to :profile
+
   end
 
   class Property < ActiveRecord::Base
   end
 
   def self.up
-    projects=Project.find(:all, :conditions => ['profile_id is not null and copy_resource_id is null'], :include => :profile)
-    projects.each do |project|
-      Property.create(:prop_key => "sonar.profile.#{project.profile.language}", :text_value => project.profile.name, :resource_id => project.id)
+    projects=Project.find(:all, :conditions => ['profile_id is not null and copy_resource_id is null'])
+    say_with_time "Processing #{projects.size} projects..." do
+      projects.each do |project|
+        profile = Profile.find(:first, :conditions => ['id=?', project.profile_id])
+        if profile
+          Property.create(:prop_key => "sonar.profile.#{profile.language}", :text_value => profile.name, :resource_id => project.id)
+        end
+      end
     end
     remove_column('projects', 'profile_id')
   end