]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5001 SONAR-5405 improve clean-up of duplicated rules and users
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 3 Jul 2014 21:28:17 +0000 (23:28 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 3 Jul 2014 21:37:29 +0000 (23:37 +0200)
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb

index 20001f1b102ce949ff7c5732627550e1b02ae391..259f667463b541d628be93fae283befa5d876a1b 100644 (file)
@@ -11,7 +11,7 @@
           [<%= message 'measure_filter.private' -%>]
         <% elsif logged_in? && @filter.user_id==current_user.id %>
           [<%= message 'measure_filter.shared_with_all_users' -%>]
-        <% elsif @filter.user_id %>
+        <% elsif @filter.user_id && @filter.user %>
           [<%= message 'shared_by' -%> <%= @filter.user.name -%>]
         <% else %>
           [<%= message 'shared_by' -%> Sonar]
index f1e0d98dde7d7352751432c16d045c6909f7f049..6cf46b031861e3e12b9feb86dd964aa1d57aae7d 100644 (file)
 require 'set'
 class InverseRuleKeyIndex < ActiveRecord::Migration
 
-  class Rule < ActiveRecord::Base
-  end
 
   class ActiveRule < ActiveRecord::Base
+    set_table_name 'active_rules'
+  end
+
+  class Characteristic < ActiveRecord::Base
+    set_table_name 'characteristics'
+  end
+
+  class Issue < ActiveRecord::Base
+    set_table_name 'issues'
+  end
+
+  class ActiveRuleChange < ActiveRecord::Base
+    set_table_name 'active_rule_changes'
   end
 
   class ProjectMeasure < ActiveRecord::Base
     set_table_name 'project_measures'
   end
 
+  class Rule < ActiveRecord::Base
+  end
+
   class RuleParameter < ActiveRecord::Base
     set_table_name 'rules_parameters'
   end
@@ -54,9 +68,12 @@ class InverseRuleKeyIndex < ActiveRecord::Migration
 
   private
   def self.delete_duplicated_rules
-    Rule.reset_column_information
     ActiveRule.reset_column_information
+    ActiveRuleChange.reset_column_information
+    Characteristic.reset_column_information
+    Issue.reset_column_information
     ProjectMeasure.reset_column_information
+    Rule.reset_column_information
     RuleParameter.reset_column_information
 
     say_with_time 'Delete duplicated rules' do
@@ -66,10 +83,13 @@ class InverseRuleKeyIndex < ActiveRecord::Migration
         key = "#{rule.plugin_name}:#{rule.plugin_rule_key}"
         if existing_keys.include?(key)
           say "Delete duplicated rule '#{key}' (id=#{rule.id})"
-          rule.destroy
           ActiveRule.delete_all(['rule_id=?', rule.id])
+          ActiveRuleChange.delete_all(['rule_id=?', rule.id])
+          Characteristic.delete_all(['rule_id=?', rule.id])
+          Issue.delete_all(['rule_id=?', rule.id])
           ProjectMeasure.delete_all(['rule_id=?', rule.id])
           RuleParameter.delete_all(['rule_id=?', rule.id])
+          rule.destroy
         else
           existing_keys.add(key)
         end
index 6aca45f8b82eaed6436958490d2e4e119cb2664e..3101ce1beefb155d582704f02ee594fe9ddc2b8d 100644 (file)
@@ -40,13 +40,30 @@ class AddMissingUserUniqueIndex < ActiveRecord::Migration
     set_table_name 'groups_users'
   end
 
+  class Dashboard < ActiveRecord::Base
+    set_table_name 'dashboards'
+    has_many :active_dashboards, :dependent => :destroy, :inverse_of => :dashboard
+  end
+
   class ActiveDashboard < ActiveRecord::Base
+    set_table_name 'active_dashboards'
+    belongs_to :dashboard
   end
 
   class PermTemplatesUser < ActiveRecord::Base
     set_table_name 'perm_templates_users'
   end
 
+  class MeasureFilter < ActiveRecord::Base
+    set_table_name 'measure_filters'
+    has_many :measure_filter_favourites, :dependent => :delete_all
+  end
+
+  class MeasureFilterFavourite < ActiveRecord::Base
+    set_table_name 'measure_filter_favourites'
+    belongs_to :measure_filter
+  end
+
   def self.up
     unless index_exists?(:users, :login, nil)
       delete_duplicated_users
@@ -60,8 +77,11 @@ class AddMissingUserUniqueIndex < ActiveRecord::Migration
     UserRole.reset_column_information
     Property.reset_column_information
     GroupsUsers.reset_column_information
+    Dashboard.reset_column_information
     ActiveDashboard.reset_column_information
     PermTemplatesUser.reset_column_information
+    MeasureFilter.reset_column_information
+    MeasureFilterFavourite.reset_column_information
 
     say_with_time 'Delete duplicated users' do
       existing_logins = Set.new
@@ -72,8 +92,11 @@ class AddMissingUserUniqueIndex < ActiveRecord::Migration
           UserRole.delete_all(['user_id=?', user.id])
           Property.delete_all(['user_id=?', user.id])
           GroupsUsers.delete_all(['user_id=?', user.id])
-          ActiveDashboard.delete_all(['user_id=?', user.id])
-          PermTemplatesUser.delete_all(['user_id=?', user.id])
+          Dashboard.destroy_all(['user_id=?', user.id])
+          ActiveDashboard.destroy_all(['user_id=?', user.id])
+          PermTemplatesUser.destroy_all(['user_id=?', user.id])
+          MeasureFilter.destroy_all(['user_id=?', user.id])
+          MeasureFilterFavourite.destroy_all(['user_id=?', user.id])
           user.destroy
         else
           existing_logins.add(user.login)