diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-19 15:01:43 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-19 15:01:43 +0200 |
commit | b2775c92005761a61dc161a26b26afefbdf1886d (patch) | |
tree | 4e4b5e86e2cbebe397fc7bf52001758ec47bfd67 /sonar-server/src | |
parent | b006b8883e0e5f3c852e610158d5ed9b39e9d196 (diff) | |
download | sonarqube-b2775c92005761a61dc161a26b26afefbdf1886d.tar.gz sonarqube-b2775c92005761a61dc161a26b26afefbdf1886d.zip |
SONAR-3889 Some rows in the table AUTHORS are duplicated
Diffstat (limited to 'sonar-server/src')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/db/migrate/351_add_unique_index_to_authors.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/351_add_unique_index_to_authors.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/351_add_unique_index_to_authors.rb new file mode 100644 index 00000000000..a9c7c1ed756 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/351_add_unique_index_to_authors.rb @@ -0,0 +1,53 @@ +# +# Sonar, open source software quality management tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# + +# +# Sonar 3.4 +# +class AddUniqueIndexToAuthors < ActiveRecord::Migration + + class Author < ActiveRecord::Base + end + + def self.up + delete_duplicated_authors + begin + add_index :authors, :login, :unique => true, :name => 'uniq_author_logins' + rescue + # Ignore, already exists + end + end + + private + def self.delete_duplicated_authors + say_with_time 'Delete duplicated authors' do + authors_by_login={} + authors=Author.find(:all, :select => 'id,login', :order => 'id') + authors.each do |author| + if authors_by_login[author.login] + # already exists + author.destroy + else + authors_by_login[author.login]=author + end + end + end + end +end |