From f206ca12ae3b445697e88fea1864c29c791196d0 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 22 Jun 2014 23:49:46 +0200 Subject: [PATCH] SONAR-5405 Do not ignore errors on creation of db index --- .../core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/persistence/rows-h2.sql | 1 + .../351_add_unique_index_to_authors.rb | 6 +--- .../db/migrate/387_create_snapshot_data.rb | 7 ++-- .../migrate/397_add_index_to_users_login.rb | 7 +--- ..._add_index_to_snapshots_root_project_id.rb | 7 +--- .../405_add_index_to_group_roles_role.rb | 7 +--- ...o_rules_plugin_rule_key_and_plugin_name.rb | 6 +--- ...33_add_index_to_characteristics_enabled.rb | 6 +--- .../532_increase_size_of_user_login.rb | 4 +-- .../db/migrate/540_create_activities_table.rb | 2 +- .../554_add_missing_user_unique_index.rb | 33 +++++++++++++++++++ 12 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index e873c66cd80..bfc0a38e095 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 553; + public static final int LAST_VERSION = 554; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 0485e75a976..0acc327fe71 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -246,6 +246,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('549'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('551'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('552'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('553'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('554'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; 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 index cc998ef24f0..9e98bb2fbde 100644 --- 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 @@ -28,11 +28,7 @@ class AddUniqueIndexToAuthors < ActiveRecord::Migration def self.up delete_duplicated_authors - begin - add_index :authors, :login, :unique => true, :name => 'uniq_author_logins' - rescue - # Ignore, already exists - end + add_index :authors, :login, :unique => true, :name => 'uniq_author_logins' end private diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/387_create_snapshot_data.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/387_create_snapshot_data.rb index cb297818210..f97f16c8ae6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/387_create_snapshot_data.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/387_create_snapshot_data.rb @@ -33,11 +33,8 @@ class CreateSnapshotData < ActiveRecord::Migration t.timestamps end - begin - add_index :snapshot_data, :snapshot_id, :name => 'snapshot_data_snapshot_id' - rescue - #ignore already existing index - end + add_index :snapshot_data, :snapshot_id, :name => 'snapshot_data_snapshot_id' + end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/397_add_index_to_users_login.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/397_add_index_to_users_login.rb index 5cd0e586451..d750fc3487e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/397_add_index_to_users_login.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/397_add_index_to_users_login.rb @@ -24,12 +24,7 @@ class AddIndexToUsersLogin < ActiveRecord::Migration def self.up - begin - add_index :users, :login, :name => 'users_login', :unique => true - rescue - # already exists - end - + add_index :users, :login, :name => 'users_login', :unique => true end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/404_add_index_to_snapshots_root_project_id.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/404_add_index_to_snapshots_root_project_id.rb index e0ae3c3b3f2..273ad93a642 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/404_add_index_to_snapshots_root_project_id.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/404_add_index_to_snapshots_root_project_id.rb @@ -24,12 +24,7 @@ class AddIndexToSnapshotsRootProjectId < ActiveRecord::Migration def self.up - begin - add_index :snapshots, :root_project_id, :name => 'snapshots_root_project_id' - rescue - # already exists - end - + add_index :snapshots, :root_project_id, :name => 'snapshots_root_project_id' end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/405_add_index_to_group_roles_role.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/405_add_index_to_group_roles_role.rb index 2d74d49659e..33dce069ae2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/405_add_index_to_group_roles_role.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/405_add_index_to_group_roles_role.rb @@ -24,12 +24,7 @@ class AddIndexToGroupRolesRole < ActiveRecord::Migration def self.up - begin - add_index :group_roles, :role, :name => 'group_roles_role' - rescue - # already exists - end - + add_index :group_roles, :role, :name => 'group_roles_role' end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/419_add_index_to_rules_plugin_rule_key_and_plugin_name.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/419_add_index_to_rules_plugin_rule_key_and_plugin_name.rb index 09e6452751b..5146886b431 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/419_add_index_to_rules_plugin_rule_key_and_plugin_name.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/419_add_index_to_rules_plugin_rule_key_and_plugin_name.rb @@ -24,11 +24,7 @@ class AddIndexToRulesPluginRuleKeyAndPluginName < ActiveRecord::Migration def self.up - begin - add_index :rules, [:plugin_rule_key, :plugin_name], :unique => true, :name => 'rules_plugin_key_and_name' - rescue - # already exists - end + add_index :rules, [:plugin_rule_key, :plugin_name], :unique => true, :name => 'rules_plugin_key_and_name' end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/433_add_index_to_characteristics_enabled.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/433_add_index_to_characteristics_enabled.rb index 2f228f3e2ac..ebeb3babbf8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/433_add_index_to_characteristics_enabled.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/433_add_index_to_characteristics_enabled.rb @@ -25,11 +25,7 @@ class AddIndexToCharacteristicsEnabled < ActiveRecord::Migration def self.up - begin - add_index :characteristics, :enabled, :name => 'characteristics_enabled' - rescue - # already exists - end + add_index :characteristics, :enabled, :name => 'characteristics_enabled' end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/532_increase_size_of_user_login.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/532_increase_size_of_user_login.rb index 393c9bf62f1..bf89707c38a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/532_increase_size_of_user_login.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/532_increase_size_of_user_login.rb @@ -45,8 +45,8 @@ class IncreaseSizeOfUserLogin < ActiveRecord::Migration change_column :users, :login, :string, :limit => 255, :unique => true if dialect()=='sqlserver' - add_index :users, :login, :name => 'users_login' - add_index :authors, :login, :unique => true, :name => 'uniq_author_logins' + add_index :users, :login, :name => 'users_login', :unique => true + add_index :authors, :login, :name => 'uniq_author_logins', :unique => true add_index :issue_filter_favourites, :user_login, :name => 'issue_filter_favs_user' add_index :issues, :assignee, :name => 'issues_assignee' end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/540_create_activities_table.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/540_create_activities_table.rb index 207b371b689..590dbac61b1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/540_create_activities_table.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/540_create_activities_table.rb @@ -33,6 +33,6 @@ class CreateActivitiesTable < ActiveRecord::Migration t.column 'log_message', :string, :limit => 4000 t.column 'log_key', :string end - add_index 'activities', :log_key, :unique => true, :name => 'activities_log_key' + add_index 'activities', :log_key, :name => 'activities_log_key', :unique => true end 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 new file mode 100644 index 00000000000..614cf41825e --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/554_add_missing_user_unique_index.rb @@ -0,0 +1,33 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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 this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 4.4 +# See SONAR-5405 +# +class AddMissingUserUniqueIndex < ActiveRecord::Migration + + def self.up + unless index_exists?(:users, :login, nil) + add_index :users, :login, :name => 'users_login', :unique => true + end + end + +end -- 2.39.5