]> source.dussan.org Git - sonarqube.git/commitdiff
Reentrant db migrations when adding/removing columns or tables 139/head
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 9 Mar 2015 11:07:07 +0000 (12:07 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 9 Mar 2015 13:44:11 +0000 (14:44 +0100)
server/sonar-web/src/main/webapp/WEB-INF/config/environment.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/540_create_activities_table.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/718_add_issue_long_dates.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/720_rename_issue_long_dates.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/721_remove_sort_field_from_issue_filters.rb

index 62d3e8094163bd81308ebfac5308582801fd139e..3e0fed4289373040d30cec19db58b34c8bc9bde1 100644 (file)
@@ -116,13 +116,31 @@ class ActiveRecord::Migration
     ActiveRecord::Base.configurations[ENV['RAILS_ENV']]['dialect']
   end
 
+  def self.column_exists?(table_name, column_name)
+    columns(table_name).any?{ |c| c.name == column_name.to_s }
+  end
+
   def self.add_index(table_name, column_name, options = {})
     # ActiveRecord can generate index names longer than 30 characters, but that's
     # not supported by Oracle, the "Enterprise" database.
     # For this reason we force to set name of indexes.
     raise ArgumentError, 'Missing index name' unless options[:name]
 
-    super(table_name, column_name, options)
+    unless index_exists?(table_name, column_name, :name => options[:name])
+      super(table_name, column_name, options)
+    end
+  end
+
+  def self.remove_column(table_name, column_name)
+    if column_exists?(table_name, column_name)
+      super(table_name, column_name)
+    end
+  end
+
+  def self.add_column(table_name, column_name, type, options = {})
+    unless column_exists?(table_name, column_name)
+      super(table_name, column_name, type, options)
+    end
   end
 
   def self.add_varchar_index(table_name, column_name, options = {})
@@ -173,8 +191,10 @@ class ActiveRecord::Migration
     # Oracle constraint (see names of triggers and indices)
     raise ArgumentError, "Table name is too long: #{table_name}" if table_name.to_s.length>25
 
-    super(table_name, options)
-    create_id_trigger(table_name) if dialect()=='oracle' && options[:id] != false
+    unless table_exists?(table_name)
+      super(table_name, options)
+      create_id_trigger(table_name) if dialect()=='oracle' && options[:id] != false
+    end
   end
 
   def drop_table(table_name, options = {})
index 590dbac61b1ee352fbf9e8ffdb00000eb7816d78..9402c05c76538499857e7478f6693d3b0b3fe4c4 100644 (file)
@@ -24,7 +24,7 @@
 #
 class CreateActivitiesTable < ActiveRecord::Migration
   def self.up
-    create_table 'activities'do |t|
+    create_table 'activities' do |t|
       t.column 'created_at',   :datetime, :null => false
       t.column 'user_login', :string, :limit => 255
       t.column 'data_field', :text
index bf0288c7f124c3775e090b0e690485f58208dae8..8ccb228a7df393c6b2f5decb80cff5e7d68d4d9b 100644 (file)
@@ -18,6 +18,9 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 
+#
+# SonarQube 5.0
+#
 class AddIssueLongDates < ActiveRecord::Migration
 
   def self.up
index e81c5659a0beb5c4dd4101b5dd5598a39a8c6a04..1e2cce5f22de198bb6776675c0dda66947b2fff9 100644 (file)
@@ -18,6 +18,9 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 
+#
+# SonarQube 5.0
+#
 class RenameIssueLongDates < ActiveRecord::Migration
 
   def self.up
index 8978b97225c6c52e5f93c16a97420799aeae416a..262b9fd2c2f0409824160e6db5b6de98c3f35154 100644 (file)
@@ -18,6 +18,9 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 
+#
+# SonarQube 5.0
+#
 class RemoveSortFieldFromIssueFilters < ActiveRecord::Migration
 
   def self.up