]> source.dussan.org Git - sonarqube.git/commitdiff
db migration : do not fail if SNAPSHOTS.VARIATION_VALUE_x columns already exist
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 22 Dec 2010 22:48:48 +0000 (22:48 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 22 Dec 2010 22:48:48 +0000 (22:48 +0000)
sonar-server/src/main/webapp/WEB-INF/db/migrate/163_add_measure_variation_values.rb

index 385be1745b1e385202ca8639b671d33664f8628f..b42ce8f440392dfab5c475d6ea93947bbd0bca60 100644 (file)
 class AddMeasureVariationValues < ActiveRecord::Migration
 
   def self.up
-    remove_column :project_measures, :diff_value_1
-    remove_column :project_measures, :diff_value_2
-    remove_column :project_measures, :diff_value_3
-    add_column(:project_measures, :variation_value_1, :decimal, :null => true, :precision => 30, :scale => 20)
-    add_column(:project_measures, :variation_value_2, :decimal, :null => true, :precision => 30, :scale => 20)
-    add_column(:project_measures, :variation_value_3, :decimal, :null => true, :precision => 30, :scale => 20)
-    add_column(:project_measures, :variation_value_4, :decimal, :null => true, :precision => 30, :scale => 20)
-    add_column(:project_measures, :variation_value_5, :decimal, :null => true, :precision => 30, :scale => 20)
+    remove_measures_column(:diff_value_1)
+    remove_measures_column(:diff_value_2)
+    remove_measures_column(:diff_value_3)
+
+    add_measures_column('variation_value_1')
+    add_measures_column('variation_value_2')
+    add_measures_column('variation_value_3')
+    add_measures_column('variation_value_4')
+    add_measures_column('variation_value_5')
+  end
+
+  private
+  def self.remove_measures_column(colname)
+    begin
+      remove_column :project_measures, colname
+    rescue
+      # already removed
+    end
   end
 
+  def self.add_measures_column(colname)
+    ProjectMeasure.reset_column_information()
+    unless ProjectMeasure.column_names.include?(name)
+      add_column(:project_measures, colname, :decimal, :null => true, :precision => 30, :scale => 20)
+    end
+  end
 end