aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-03 23:28:17 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-03 23:28:17 +0200
commite2853ac9b907dc14d43f4d285067cb8503bfa45c (patch)
tree52c9a2e8c71eb0b7d238d7ebd7861aab86d243a2 /sonar-server/src/main/webapp
parent0768d4dad34c8de286ae3f7dbe934d316ad1d264 (diff)
downloadsonarqube-e2853ac9b907dc14d43f4d285067cb8503bfa45c.tar.gz
sonarqube-e2853ac9b907dc14d43f4d285067cb8503bfa45c.zip
SONAR-5001 SONAR-5405 improve clean-up of duplicated rules and users
Diffstat (limited to 'sonar-server/src/main/webapp')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb28
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb27
3 files changed, 50 insertions, 7 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb
index 20001f1b102..259f667463b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_search_header.html.erb
@@ -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]
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb
index f1e0d98dde7..6cf46b03186 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/546_inverse_rule_key_index.rb
@@ -25,16 +25,30 @@
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
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb
index 6aca45f8b82..3101ce1beef 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb
@@ -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)