From eb451f2c3aafc231cf05c81ff3e94f73b98ee586 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 7 Jul 2020 12:13:36 -0500 Subject: [PATCH] SONAR-13594 Upgrade to 8.4 fails on MS SQL Server --- .../main/java/org/sonar/db/DatabaseUtils.java | 49 +++++++++++------ .../java/org/sonar/db/DatabaseUtilsTest.java | 47 +++++++++++----- .../db/DatabaseUtilsTest/just_one_table.sql | 3 -- .../org/sonar/db/DatabaseUtilsTest/sql.sql | 7 +++ .../java/org/sonar/db/CoreDbTester.java | 6 ++- .../java/org/sonar/db/CoreTestDb.java | 19 ++++--- .../db/migration/def/Validations.java | 28 ++++++++-- .../db/migration/sql/DropIndexBuilder.java | 16 +----- .../db/migration/step/DropIndexChange.java | 53 +++++++++++++++++++ .../AddIndexOnSlugOfProjectAlmSettings.java | 2 +- ...veRuleUuidOfActiveRuleParametersTable.java | 2 +- ...tiveRuleIdOfActiveRuleParametersTable.java | 26 ++------- ...UniqueIndexOnUuidColumnOfCeQueueTable.java | 19 ++----- .../AddIndexOnGroupUuidOfGroupRolesTable.java | 2 +- .../DropIndexOnGroupIdOfGroupRolesTable.java | 26 ++------- ...AddIndexOnGroupUuidOfGroupsUsersTable.java | 2 +- .../DropIndexOnGroupIdOfGroupsUsersTable.java | 25 ++++----- ...xOnGroupUuidOfQProfileEditGroupsTable.java | 2 +- ...dexOnGroupIdOfQProfileEditGroupsTable.java | 26 ++------- ...AddIndexOnIssueKeyOfIssueChangesTable.java | 2 +- .../AddIndexOnKeeOfIssueChangesTable.java | 2 +- ...dIndexOnMetricUuidOfLiveMeasuresTable.java | 2 +- ...IndexOnProjectUuidOfLiveMeasuresTable.java | 2 +- ...dexOnMetricUuidOfProjectMeasuresTable.java | 2 +- ...IndexOnMetricIdOfProjectMeasuresTable.java | 26 ++------- ...yColumnsOfPermTplCharacteristicsTable.java | 2 +- ...yColumnsOfPermTplCharacteristicsTable.java | 26 ++------- ...TechIndexOnUuidOfProjectMeasuresTable.java | 2 +- ...TechIndexOnUuidOfProjectMeasuresTable.java | 25 ++------- ...eIndexOnUuidColumnOfQualityGatesTable.java | 18 ++----- .../AddIndexToActiveRulesTable.java | 2 +- ...IndexOnRuleIdColumnOfActiveRulesTable.java | 17 ++---- .../AddIndexToDeprecatedRuleKeysTable.java | 2 +- ...RuleIdColumnOfDeprecatedRuleKeysTable.java | 19 ++----- .../rules/issues/AddIndexesToIssuesTable.java | 2 +- .../AddIndexesToRulesParametersTable.java | 2 +- ...sOnRuleIdColumnOfRulesParametersTable.java | 23 +++++--- ...eIndexOnKeeColumnOfRulesProfilesTable.java | 26 ++------- ...OnProfileUuidColumnOfActiveRulesTable.java | 2 +- ...exOnProfileIdColumnOfActiveRulesTable.java | 26 ++------- ...opUniqueIndexOnUuidColumnOfUsersTable.java | 26 ++------- .../AddIndexOnUserUuidOfGroupsUsersTable.java | 2 +- ...nUserUuidAndGroupIdOfGroupsUsersTable.java | 2 +- .../DropIndexOnUserIdOfGroupsUsersTable.java | 26 ++------- ...xOnUserIdAndGroupIdOfGroupsUsersTable.java | 25 ++------- ...xOnUserUuidOfOrganizationMembersTable.java | 2 +- ...dexOnUserIdOfOrganizationMembersTable.java | 26 ++------- ...dQProfileUuidOfQProfileEditUsersTable.java | 2 +- ...dQProfileUuidOfQProfileEditUsersTable.java | 26 ++------- .../AddIndexOnUserUuidOfUserRolesTable.java | 2 +- .../DropIndexOnUserIdOfUserRolesTable.java | 26 ++------- .../db/migration/def/ValidationsTest.java | 2 +- .../migration/sql/CreateIndexBuilderTest.java | 4 +- .../migration/sql/CreateTableBuilderTest.java | 4 +- .../migration/sql/DropIndexBuilderTest.java | 6 +-- 55 files changed, 288 insertions(+), 483 deletions(-) delete mode 100644 server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/just_one_table.sql create mode 100644 server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/sql.sql create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java index fff31a94824..ff53e51f5d8 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java @@ -39,6 +39,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import java.util.function.IntFunction; @@ -282,10 +283,10 @@ public class DatabaseUtils { } /** - * @param table case-insensitive name of table - * @return true if a table exists with this name, otherwise false - * @throws SQLException - */ + * @param table case-insensitive name of table + * @return true if a table exists with this name, otherwise false + * @throws SQLException + */ public static boolean tableExists(String table, Connection connection) { return doTableExists(table, connection) || doTableExists(table.toLowerCase(Locale.ENGLISH), connection) || @@ -310,25 +311,43 @@ public class DatabaseUtils { } } - public static boolean indexExists(String table, String index, Connection connection) { - return doIndexExists(table, index, connection) || - doIndexExists(table.toLowerCase(Locale.ENGLISH), index, connection) || - doIndexExists(table.toUpperCase(Locale.ENGLISH), index, connection); + public static boolean indexExistsIgnoreCase(String table, String index, Connection connection) { + return doIndexExistsIgnoreIndexCase(table, index, connection) || + doIndexExistsIgnoreIndexCase(table.toLowerCase(Locale.ENGLISH), index, connection) || + doIndexExistsIgnoreIndexCase(table.toUpperCase(Locale.ENGLISH), index, connection); + } + + private static boolean doIndexExistsIgnoreIndexCase(String table, String index, Connection connection) { + return findIndex(connection, table, index).isPresent(); } - private static boolean doIndexExists(String table, String index, Connection connection) { + /** + * Finds an index by searching by its lower case or upper case name. If an index is found, it's name is returned with the matching case. + * This is useful when we need to drop an index that could exist with either lower case or upper case name. + * See SONAR-13594 + */ + public static Optional findExistingIndex(Connection connection, String tableName, String indexName) { + Optional result = findIndex(connection, tableName.toLowerCase(Locale.US), indexName); + if (result.isPresent()) { + return result; + } + // in tests, tables have uppercase name + return findIndex(connection, tableName.toUpperCase(Locale.US), indexName); + } + + private static Optional findIndex(Connection connection, String tableName, String indexName) { String schema = getSchema(connection); - try (ResultSet rs = connection.getMetaData().getIndexInfo(connection.getCatalog(), schema, table, false, true)) { + try (ResultSet rs = connection.getMetaData().getIndexInfo(connection.getCatalog(), schema, tableName, false, true)) { while (rs.next()) { - String indexName = rs.getString("INDEX_NAME"); - if (index.equalsIgnoreCase(indexName)) { - return true; + String idx = rs.getString("INDEX_NAME"); + if (indexName.equalsIgnoreCase(idx)) { + return Optional.of(idx); } } - return false; + return Optional.empty(); } catch (SQLException e) { - throw wrapSqlException(e, "Can not check that table %s exists", table); + throw wrapSqlException(e, "Can not check that table %s exists", tableName); } } diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java index 383133974c5..7342a0a47c5 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Objects; import javax.annotation.Nullable; import org.junit.Rule; @@ -57,19 +58,41 @@ import static org.sonar.db.DatabaseUtils.toUniqueAndSortedList; public class DatabaseUtilsTest { @Rule - public CoreDbTester dbTester = CoreDbTester.createForSchema(DatabaseUtilsTest.class, "just_one_table.sql"); + public CoreDbTester dbTester = CoreDbTester.createForSchema(DatabaseUtilsTest.class, "sql.sql", false); @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule public LogTester logTester = new LogTester(); + @Test + public void find_index_with_lower_case() throws SQLException { + String tableName = "schema_migrations"; + String indexName = "lower_case_name"; + try (Connection connection = dbTester.openConnection()) { + assertThat(DatabaseUtils.findExistingIndex(connection, tableName, indexName)).contains(indexName); + assertThat(DatabaseUtils.findExistingIndex(connection, tableName.toLowerCase(Locale.US), indexName)).contains(indexName); + } + } + + @Test + public void find_index_with_upper_case() throws SQLException { + String tableName = "schema_migrations"; + String indexName = "UPPER_CASE_NAME"; + try (Connection connection = dbTester.openConnection()) { + assertThat(DatabaseUtils.findExistingIndex(connection, tableName, indexName)).contains(indexName); + assertThat(DatabaseUtils.findExistingIndex(connection, tableName, indexName.toLowerCase(Locale.US))).contains(indexName); + assertThat(DatabaseUtils.findExistingIndex(connection, tableName.toLowerCase(Locale.US), indexName.toLowerCase(Locale.US))).contains(indexName); + } + } + @Test public void should_close_connection() throws Exception { - Connection connection = dbTester.openConnection(); - assertThat(isClosed(connection)).isFalse(); + try (Connection connection = dbTester.openConnection()) { + assertThat(isClosed(connection)).isFalse(); - DatabaseUtils.closeQuietly(connection); - assertThat(isClosed(connection)).isTrue(); + DatabaseUtils.closeQuietly(connection); + assertThat(isClosed(connection)).isTrue(); + } } @Test @@ -80,9 +103,7 @@ public class DatabaseUtilsTest { @Test public void should_close_statement_and_resultset() throws Exception { - Connection connection = dbTester.openConnection(); - try { - PreparedStatement statement = connection.prepareStatement(selectDual()); + try (Connection connection = dbTester.openConnection(); PreparedStatement statement = connection.prepareStatement(selectDual())) { ResultSet rs = statement.executeQuery(); DatabaseUtils.closeQuietly(rs); @@ -90,8 +111,6 @@ public class DatabaseUtilsTest { assertThat(isClosed(statement)).isTrue(); assertThat(isClosed(rs)).isTrue(); - } finally { - DatabaseUtils.closeQuietly(connection); } } @@ -167,8 +186,8 @@ public class DatabaseUtilsTest { public void toUniqueAndSortedList_removes_duplicates_and_apply_natural_order_of_any_Comparable() { assertThat( toUniqueAndSortedList(asList(myComparable(2), myComparable(5), myComparable(2), myComparable(4), myComparable(-1), myComparable(10)))) - .containsExactly( - myComparable(-1), myComparable(2), myComparable(4), myComparable(5), myComparable(10)); + .containsExactly( + myComparable(-1), myComparable(2), myComparable(4), myComparable(5), myComparable(10)); } private static DatabaseUtilsTest.MyComparable myComparable(int ordinal) { @@ -291,8 +310,8 @@ public class DatabaseUtilsTest { }, i -> i / 500); - assertThat(outputs).containsExactly(1,2,3); - assertThat(partitions).containsExactly(asList(1,2), asList(3)); + assertThat(outputs).containsExactly(1, 2, 3); + assertThat(partitions).containsExactly(asList(1, 2), asList(3)); } @Test diff --git a/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/just_one_table.sql b/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/just_one_table.sql deleted file mode 100644 index a1019056ef5..00000000000 --- a/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/just_one_table.sql +++ /dev/null @@ -1,3 +0,0 @@ -CREATE TABLE "SCHEMA_MIGRATIONS" ( - "VERSION" VARCHAR(256) NOT NULL -); diff --git a/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/sql.sql b/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/sql.sql new file mode 100644 index 00000000000..ec4b8782e31 --- /dev/null +++ b/server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/sql.sql @@ -0,0 +1,7 @@ +CREATE TABLE "schema_migrations" ( + "version" VARCHAR(256) NOT NULL +); + +CREATE INDEX UPPER_CASE_NAME ON schema_migrations (version); + +CREATE INDEX lower_case_name ON schema_migrations (version); diff --git a/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreDbTester.java b/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreDbTester.java index f55338c174a..c4c14117b82 100644 --- a/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreDbTester.java +++ b/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreDbTester.java @@ -34,9 +34,13 @@ public class CoreDbTester extends AbstractDbTester { } public static CoreDbTester createForSchema(Class testClass, String filename) { + return createForSchema(testClass, filename, true); + } + + public static CoreDbTester createForSchema(Class testClass, String filename, boolean databaseToUpper) { String path = StringUtils.replaceChars(testClass.getCanonicalName(), '.', '/'); String schemaPath = path + "/" + filename; - return new CoreDbTester(CoreTestDb.create(schemaPath)); + return new CoreDbTester(CoreTestDb.create(schemaPath, databaseToUpper)); } public static CoreDbTester createEmpty() { diff --git a/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreTestDb.java b/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreTestDb.java index 56d6821f9f7..c1c5c0dfdf8 100644 --- a/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreTestDb.java +++ b/server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreTestDb.java @@ -28,10 +28,9 @@ import java.util.function.Consumer; import java.util.function.Function; import javax.annotation.Nullable; import javax.sql.DataSource; -import org.apache.commons.codec.digest.DigestUtils; import org.junit.AssumptionViolatedException; -import org.sonar.api.config.internal.Settings; import org.sonar.api.config.internal.MapSettings; +import org.sonar.api.config.internal.Settings; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.db.version.SqTables; @@ -63,16 +62,20 @@ class CoreTestDb implements TestDb { } static CoreTestDb create(String schemaPath) { + return create(schemaPath, true); + } + + static CoreTestDb create(String schemaPath, boolean databaseToUpper) { requireNonNull(schemaPath, "schemaPath can't be null"); - return new CoreTestDb().init(schemaPath); + return new CoreTestDb().init(schemaPath, databaseToUpper); } static CoreTestDb createEmpty() { - return new CoreTestDb().init(null); + return new CoreTestDb().init(null, true); } - private CoreTestDb init(@Nullable String schemaPath) { + private CoreTestDb init(@Nullable String schemaPath, boolean databaseToUpper) { Consumer noExtraSettingsLoaded = settings -> { }; Function databaseCreator = settings -> { @@ -83,7 +86,11 @@ class CoreTestDb implements TestDb { throw new AssumptionViolatedException("This test is intended to be run on H2 only"); } - return new CoreH2Database("h2Tests-" + (schemaPath == null ? "empty" : DigestUtils.md5Hex(schemaPath))); + String name = "\"h2Tests-\" + (schemaPath == null ? \"empty\" : DigestUtils.md5Hex(schemaPath))"; + if (!databaseToUpper) { + name = name + ";DATABASE_TO_UPPER=FALSE"; + } + return new CoreH2Database(name); }; Consumer databaseInitializer = database -> { if (schemaPath == null) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/Validations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/Validations.java index fb9abe2a901..b09eb4ad51a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/Validations.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/Validations.java @@ -36,6 +36,7 @@ public class Validations { private static final CharMatcher DIGIT_CHAR_MATCHER = inRange('0', '9'); private static final CharMatcher LOWER_CASE_ASCII_LETTERS_CHAR_MATCHER = inRange('a', 'z'); + private static final CharMatcher UPPER_CASE_ASCII_LETTERS_CHAR_MATCHER = inRange('A', 'Z'); private static final CharMatcher UNDERSCORE_CHAR_MATCHER = anyOf("_"); private Validations() { @@ -63,7 +64,6 @@ public class Validations { * @see #checkDbIdentifier(String, String, int) */ public static String validateTableName(@Nullable String tableName) { - requireNonNull(tableName, "Table name cannot be null"); checkDbIdentifier(tableName, "Table name", TABLE_NAME_MAX_SIZE); return tableName; } @@ -76,7 +76,6 @@ public class Validations { * @see #checkDbIdentifier(String, String, int) */ public static String validateConstraintName(@Nullable String constraintName) { - requireNonNull(constraintName, "Constraint name cannot be null"); checkDbIdentifier(constraintName, "Constraint name", CONSTRAINT_NAME_MAX_SIZE); return constraintName; } @@ -89,11 +88,15 @@ public class Validations { * @see #checkDbIdentifier(String, String, int) */ public static String validateIndexName(@Nullable String indexName) { - requireNonNull(indexName, "Index name cannot be null"); checkDbIdentifier(indexName, "Index name", INDEX_NAME_MAX_SIZE); return indexName; } + public static String validateIndexNameIgnoreCase(@Nullable String indexName) { + checkDbIdentifier(indexName, "Index name", INDEX_NAME_MAX_SIZE, true); + return indexName; + } + /** * Ensure {@code identifier} is a valid DB identifier. * @@ -105,12 +108,20 @@ public class Validations { * @throws IllegalArgumentException if {@code identifier} starts with {@code _} or a number */ static String checkDbIdentifier(@Nullable String identifier, String identifierDesc, int maxSize) { + return checkDbIdentifier(identifier, identifierDesc, maxSize, false); + } + + static String checkDbIdentifier(@Nullable String identifier, String identifierDesc, int maxSize, boolean ignoreCase) { String res = checkNotNull(identifier, "%s can't be null", identifierDesc); checkArgument(!res.isEmpty(), "%s, can't be empty", identifierDesc); checkArgument( identifier.length() <= maxSize, "%s length can't be more than %s", identifierDesc, maxSize); - checkDbIdentifierCharacters(identifier, identifierDesc); + if (ignoreCase) { + checkDbIdentifierCharactersIgnoreCase(identifier, identifierDesc); + } else { + checkDbIdentifierCharacters(identifier, identifierDesc); + } return res; } @@ -123,4 +134,13 @@ public class Validations { DIGIT_CHAR_MATCHER.or(UNDERSCORE_CHAR_MATCHER).matchesNoneOf(identifier.subSequence(0, 1)), "%s must not start by a number or '_', got '%s'", identifierDesc, identifier); } + + private static void checkDbIdentifierCharactersIgnoreCase(String identifier, String identifierDesc) { + checkArgument(identifier.length() > 0, "Identifier must not be empty"); + checkArgument(LOWER_CASE_ASCII_LETTERS_CHAR_MATCHER.or(DIGIT_CHAR_MATCHER).or(UPPER_CASE_ASCII_LETTERS_CHAR_MATCHER).or(anyOf("_")).matchesAllOf(identifier), + "%s must contain only alphanumeric chars or '_', got '%s'", identifierDesc, identifier); + checkArgument( + DIGIT_CHAR_MATCHER.or(UNDERSCORE_CHAR_MATCHER).matchesNoneOf(identifier.subSequence(0, 1)), + "%s must not start by a number or '_', got '%s'", identifierDesc, identifier); + } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilder.java index 1d77ba7864a..936340783b9 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilder.java @@ -19,11 +19,7 @@ */ package org.sonar.server.platform.db.migration.sql; -import java.sql.Connection; -import java.sql.SQLException; import java.util.List; -import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.H2; import org.sonar.db.dialect.MsSql; @@ -31,7 +27,7 @@ import org.sonar.db.dialect.Oracle; import org.sonar.db.dialect.PostgreSql; import static java.util.Collections.singletonList; -import static org.sonar.server.platform.db.migration.def.Validations.validateIndexName; +import static org.sonar.server.platform.db.migration.def.Validations.validateIndexNameIgnoreCase; import static org.sonar.server.platform.db.migration.def.Validations.validateTableName; public class DropIndexBuilder { @@ -56,7 +52,7 @@ public class DropIndexBuilder { public List build() { validateTableName(tableName); - validateIndexName(indexName); + validateIndexNameIgnoreCase(indexName); return singletonList(createSqlStatement()); } @@ -73,12 +69,4 @@ public class DropIndexBuilder { throw new IllegalStateException("Unsupported dialect for drop of index: " + dialect); } } - - public boolean indexExists(Database database) throws SQLException { - validateTableName(tableName); - validateIndexName(indexName); - try (Connection connection = database.getDataSource().getConnection()) { - return DatabaseUtils.indexExists(tableName, indexName, connection); - } - } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java new file mode 100644 index 00000000000..0fd734546b7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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. + */ +package org.sonar.server.platform.db.migration.step; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Optional; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; + +public abstract class DropIndexChange extends DdlChange { + private final String indexName; + private final String tableName; + + public DropIndexChange(Database db, String indexName, String tableName) { + super(db); + this.indexName = indexName; + this.tableName = tableName; + } + + @Override + public void execute(Context context) throws SQLException { + Optional indexName = findExistingIndexName(); + indexName.ifPresent(index -> context.execute(new DropIndexBuilder(getDialect()) + .setTable(tableName) + .setName(index) + .build())); + } + + private Optional findExistingIndexName() throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + return DatabaseUtils.findExistingIndex(connection, tableName, indexName); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/AddIndexOnSlugOfProjectAlmSettings.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/AddIndexOnSlugOfProjectAlmSettings.java index 974a0eb69d9..6349e4bd62a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/AddIndexOnSlugOfProjectAlmSettings.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/AddIndexOnSlugOfProjectAlmSettings.java @@ -58,7 +58,7 @@ public class AddIndexOnSlugOfProjectAlmSettings extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java index 26bfea0a4f3..9d4cabeeef7 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java @@ -55,7 +55,7 @@ public class AddIndexOnActiveRuleUuidOfActiveRuleParametersTable extends DdlChan private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java index b8df35a9fe7..ddc4b1a0387 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.activerules; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnActiveRuleIdOfActiveRuleParametersTable extends DdlChange { +public class DropIndexOnActiveRuleIdOfActiveRuleParametersTable extends DropIndexChange { private static final String TABLE_NAME = "active_rule_parameters"; private static final String INDEX_NAME = "ix_arp_on_active_rule_id"; public DropIndexOnActiveRuleIdOfActiveRuleParametersTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java index 5f898380b2f..f3665469759 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java @@ -19,23 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.cequeue; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnUuidColumnOfCeQueueTable extends DdlChange { +public class DropUniqueIndexOnUuidColumnOfCeQueueTable extends DropIndexChange { + private static final String TABLE_NAME = "ce_queue"; + private static final String INDEX_NAME = "ce_queue_uuid"; public DropUniqueIndexOnUuidColumnOfCeQueueTable(Database db) { - super(db); + super(db, INDEX_NAME, TABLE_NAME); } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable("ce_queue") - .setName("ce_queue_uuid") - .build()); - } - } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java index d7d99463837..e60e5079529 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java @@ -70,7 +70,7 @@ public class AddIndexOnGroupUuidOfGroupRolesTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java index 93f6dbe7216..005de5c9c3a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.groups.grouproles; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnGroupIdOfGroupRolesTable extends DdlChange { +public class DropIndexOnGroupIdOfGroupRolesTable extends DropIndexChange { private static final String TABLE_NAME = "group_roles"; private static final String INDEX_NAME = "uniq_group_roles"; public DropIndexOnGroupIdOfGroupRolesTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java index ecb0f5d36bc..6f6c7930a61 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java @@ -70,7 +70,7 @@ public class AddIndexOnGroupUuidOfGroupsUsersTable extends DdlChange { private boolean indexExists(String name) throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, name, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, name, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java index 3b01f284cd0..a087126ff27 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java @@ -21,6 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.groups.groupsusers; import java.sql.Connection; import java.sql.SQLException; +import java.util.Optional; +import java.util.function.Consumer; import org.sonar.db.Database; import org.sonar.db.DatabaseUtils; import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; @@ -37,23 +39,18 @@ public class DropIndexOnGroupIdOfGroupsUsersTable extends DdlChange { @Override public void execute(Context context) throws SQLException { - if (indexExists(INDEX_NAME1)) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME1) - .build()); - } - if (indexExists(INDEX_NAME2)) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME2) - .build()); - } + Consumer dropIndex = idx -> context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName(idx) + .build()); + + findExistingIndexName(INDEX_NAME1).ifPresent(dropIndex); + findExistingIndexName(INDEX_NAME2).ifPresent(dropIndex); } - private boolean indexExists(String name) throws SQLException { + private Optional findExistingIndexName(String indexName) throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, name, connection); + return DatabaseUtils.findExistingIndex(connection, TABLE_NAME, indexName); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java index 2029b8b2499..9d5989e6a85 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java @@ -60,7 +60,7 @@ public class AddIndexOnGroupUuidOfQProfileEditGroupsTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java index d64275b6a6a..9cccc40f554 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.groups.qprofileeditgroups; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnGroupIdOfQProfileEditGroupsTable extends DdlChange { +public class DropIndexOnGroupIdOfQProfileEditGroupsTable extends DropIndexChange { private static final String TABLE_NAME = "qprofile_edit_groups"; private static final String INDEX_NAME = "qprofile_edit_groups_unique"; public DropIndexOnGroupIdOfQProfileEditGroupsTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists(INDEX_NAME)) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists(String name) throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, name, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java index 9e39b935d50..268c8400ccd 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java @@ -54,7 +54,7 @@ public class AddIndexOnIssueKeyOfIssueChangesTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java index 56cb5019ae1..93e5234f465 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java @@ -54,7 +54,7 @@ public class AddIndexOnKeeOfIssueChangesTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java index d92a46e3df0..9537d32cefe 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java @@ -60,7 +60,7 @@ public class AddIndexOnMetricUuidOfLiveMeasuresTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java index 0a257945a07..86b29fb8bba 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java @@ -55,7 +55,7 @@ public class AddIndexOnProjectUuidOfLiveMeasuresTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java index 8f6b8f37404..f9f70153a0d 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java @@ -60,7 +60,7 @@ public class AddIndexOnMetricUuidOfProjectMeasuresTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java index 7c632957917..338f4f57bb2 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.metrics.projectmeasures; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnMetricIdOfProjectMeasuresTable extends DdlChange { +public class DropIndexOnMetricIdOfProjectMeasuresTable extends DropIndexChange { private static final String TABLE_NAME = "project_measures"; private static final String INDEX_NAME = "measures_analysis_metric"; public DropIndexOnMetricIdOfProjectMeasuresTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java index ba455bb4651..f9d582670a6 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java @@ -61,7 +61,7 @@ public class AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharact private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java index e1797a97ea3..939e0840c35 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.permissiontemplates.fk.permtplcharacteristics; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable extends DdlChange { +public class DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable extends DropIndexChange { private static final String TABLE_NAME = "perm_tpl_characteristics"; private static final String INDEX_NAME = "uniq_perm_tpl_charac"; public DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddTechIndexOnUuidOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddTechIndexOnUuidOfProjectMeasuresTable.java index 9e4a37657d1..1e34df9a063 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddTechIndexOnUuidOfProjectMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddTechIndexOnUuidOfProjectMeasuresTable.java @@ -55,7 +55,7 @@ public class AddTechIndexOnUuidOfProjectMeasuresTable extends DdlChange { private boolean indexExists(String name) throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, name, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, name, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropTechIndexOnUuidOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropTechIndexOnUuidOfProjectMeasuresTable.java index e1d0705c1aa..33503ec947a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropTechIndexOnUuidOfProjectMeasuresTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropTechIndexOnUuidOfProjectMeasuresTable.java @@ -19,34 +19,15 @@ */ package org.sonar.server.platform.db.migration.version.v84.projectmeasures; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropTechIndexOnUuidOfProjectMeasuresTable extends DdlChange { +public class DropTechIndexOnUuidOfProjectMeasuresTable extends DropIndexChange { private static final String TABLE_NAME = "project_measures"; private static final String INDEX_NAME = "tech_index_uuid"; public DropTechIndexOnUuidOfProjectMeasuresTable(Database db) { - super(db); + super(db, INDEX_NAME, TABLE_NAME); } - @Override - public void execute(Context context) throws SQLException { - if (indexExists(INDEX_NAME)) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists(String name) throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, name, connection); - } - } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java index 6e51337ef03..cfbb48c8ac4 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java @@ -19,22 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.qualitygates; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnUuidColumnOfQualityGatesTable extends DdlChange { +public class DropUniqueIndexOnUuidColumnOfQualityGatesTable extends DropIndexChange { + private static final String INDEX_NAME = "uniq_quality_gates_uuid"; + private static final String TABLE_NAME = "quality_gates"; public DropUniqueIndexOnUuidColumnOfQualityGatesTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable("quality_gates") - .setName("uniq_quality_gates_uuid") - .build()); + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/AddIndexToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/AddIndexToActiveRulesTable.java index 021c54c9f75..bb052873e15 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/AddIndexToActiveRulesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/AddIndexToActiveRulesTable.java @@ -63,7 +63,7 @@ public class AddIndexToActiveRulesTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE, INDEX_NAME, connection); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java index 0ba65c96767..d993272acd0 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java @@ -19,25 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.rules.activerules; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnRuleIdColumnOfActiveRulesTable extends DdlChange { +public class DropIndexOnRuleIdColumnOfActiveRulesTable extends DropIndexChange { private static final String TABLE_NAME = "active_rules"; private static final String INDEX_NAME = "uniq_profile_rule_ids"; public DropIndexOnRuleIdColumnOfActiveRulesTable(Database db) { - super(db); + super(db, INDEX_NAME, TABLE_NAME); } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java index b15ecfc3ade..f998365c3fd 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java @@ -56,7 +56,7 @@ public class AddIndexToDeprecatedRuleKeysTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE, INDEX_NAME, connection); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java index 9aea9da32cf..8ec1dab354c 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java @@ -19,23 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.rules.deprecatedrulekeys; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable extends DdlChange { +public class DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable extends DropIndexChange { + private static final String TABLE_NAME = "deprecated_rule_keys"; + private static final String INDEX_NAME = "rule_id_deprecated_rule_keys"; public DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable(Database db) { - super(db); + super(db, INDEX_NAME, TABLE_NAME); } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable("deprecated_rule_keys") - .setName("rule_id_deprecated_rule_keys") - .build()); - } - } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java index f0f8aa59a2f..81e8fb1c8ea 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java @@ -99,7 +99,7 @@ public class AddIndexesToIssuesTable extends DdlChange { private boolean indexExists(String name) throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE, name, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE, name, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/AddIndexesToRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/AddIndexesToRulesParametersTable.java index ea2e66feb50..c6f29480148 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/AddIndexesToRulesParametersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/AddIndexesToRulesParametersTable.java @@ -74,7 +74,7 @@ public class AddIndexesToRulesParametersTable extends DdlChange { private boolean indexDoesNotExist(String index) throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return !DatabaseUtils.indexExists(TABLE, index, connection); + return !DatabaseUtils.indexExistsIgnoreCase(TABLE, index, connection); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java index 9d2d4667d94..ed1402f8849 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java @@ -19,12 +19,17 @@ */ package org.sonar.server.platform.db.migration.version.v84.rules.rulesparameters; +import java.sql.Connection; import java.sql.SQLException; +import java.util.Optional; +import java.util.function.Consumer; import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; import org.sonar.server.platform.db.migration.step.DdlChange; public class DropIndexesOnRuleIdColumnOfRulesParametersTable extends DdlChange { + private static final String TABLE_NAME = "rules_parameters"; public DropIndexesOnRuleIdColumnOfRulesParametersTable(Database db) { super(db); @@ -32,14 +37,18 @@ public class DropIndexesOnRuleIdColumnOfRulesParametersTable extends DdlChange { @Override public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable("rules_parameters") - .setName("rules_parameters_rule_id") - .build()); - context.execute(new DropIndexBuilder(getDialect()) - .setTable("rules_parameters") - .setName("rules_parameters_unique") + Consumer dropIndex = idx -> context.execute(new DropIndexBuilder(getDialect()) + .setTable(TABLE_NAME) + .setName(idx) .build()); + + findExistingIndexName("rules_parameters_rule_id").ifPresent(dropIndex); + findExistingIndexName("rules_parameters_unique").ifPresent(dropIndex); } + private Optional findExistingIndexName(String indexName) throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + return DatabaseUtils.findExistingIndex(connection, TABLE_NAME, indexName); + } + } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java index ca55e835a2b..70640deaa65 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.rulesprofiles; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnKeeColumnOfRulesProfilesTable extends DdlChange { +public class DropUniqueIndexOnKeeColumnOfRulesProfilesTable extends DropIndexChange { private static final String TABLE_NAME = "rules_profiles"; private static final String INDEX_NAME = "uniq_qprof_key"; public DropUniqueIndexOnKeeColumnOfRulesProfilesTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java index 8c856cd86e1..6bb024790ed 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java @@ -61,7 +61,7 @@ public class AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable extends DdlChan private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java index 7241cfe4b19..0d1e570d1c2 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.rulesprofiles.fk.activerules; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnProfileIdColumnOfActiveRulesTable extends DdlChange { +public class DropUniqueIndexOnProfileIdColumnOfActiveRulesTable extends DropIndexChange { private static final String TABLE_NAME = "active_rules"; private static final String INDEX_NAME = "uniq_profile_rule_ids"; public DropUniqueIndexOnProfileIdColumnOfActiveRulesTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropUniqueIndexOnUuidColumnOfUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropUniqueIndexOnUuidColumnOfUsersTable.java index 0e5ba8d20c2..8c277cd871b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropUniqueIndexOnUuidColumnOfUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropUniqueIndexOnUuidColumnOfUsersTable.java @@ -19,35 +19,15 @@ */ package org.sonar.server.platform.db.migration.version.v84.users; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnUuidColumnOfUsersTable extends DdlChange { +public class DropUniqueIndexOnUuidColumnOfUsersTable extends DropIndexChange { private static final String TABLE_NAME = "users"; private static final String INDEX_NAME = "users_uuid"; public DropUniqueIndexOnUuidColumnOfUsersTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddIndexOnUserUuidOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddIndexOnUserUuidOfGroupsUsersTable.java index 3a47ef73200..2af95ce6487 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddIndexOnUserUuidOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddIndexOnUserUuidOfGroupsUsersTable.java @@ -54,7 +54,7 @@ public class AddIndexOnUserUuidOfGroupsUsersTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.java index 0c9179c5dc6..0facd88fbf8 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.java @@ -58,7 +58,7 @@ public class AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable extends DdlCha private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropIndexOnUserIdOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropIndexOnUserIdOfGroupsUsersTable.java index 4df0d1b7de6..abad87f06ac 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropIndexOnUserIdOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropIndexOnUserIdOfGroupsUsersTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.users.fk.groupsusers; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnUserIdOfGroupsUsersTable extends DdlChange { +public class DropIndexOnUserIdOfGroupsUsersTable extends DropIndexChange { private static final String TABLE_NAME = "groups_users"; private static final String INDEX_NAME = "index_groups_users_on_user_id"; public DropIndexOnUserIdOfGroupsUsersTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable.java index 7afb9cd4d51..0822650a4d2 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable.java @@ -19,34 +19,15 @@ */ package org.sonar.server.platform.db.migration.version.v84.users.fk.groupsusers; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable extends DdlChange { +public class DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable extends DropIndexChange { private static final String TABLE_NAME = "groups_users"; private static final String INDEX_NAME = "groups_users_unique"; public DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable(Database db) { - super(db); + super(db, INDEX_NAME, TABLE_NAME); } - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } - } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddIndexOnUserUuidOfOrganizationMembersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddIndexOnUserUuidOfOrganizationMembersTable.java index 21fb387e9e5..9010f8fd65c 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddIndexOnUserUuidOfOrganizationMembersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddIndexOnUserUuidOfOrganizationMembersTable.java @@ -54,7 +54,7 @@ public class AddIndexOnUserUuidOfOrganizationMembersTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropIndexOnUserIdOfOrganizationMembersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropIndexOnUserIdOfOrganizationMembersTable.java index 90b8196a1b7..9fc81b47133 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropIndexOnUserIdOfOrganizationMembersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropIndexOnUserIdOfOrganizationMembersTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.users.fk.organizationmembers; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnUserIdOfOrganizationMembersTable extends DdlChange { +public class DropIndexOnUserIdOfOrganizationMembersTable extends DropIndexChange { private static final String TABLE_NAME = "organization_members"; private static final String INDEX_NAME = "ix_org_members_on_user_id"; public DropIndexOnUserIdOfOrganizationMembersTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.java index 38eb2e8f973..8dd7f371ce0 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.java @@ -58,7 +58,7 @@ public class AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable ext private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.java index eafca322d16..82afc9ba268 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.users.fk.qprofileeditusers; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable extends DdlChange { +public class DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable extends DropIndexChange { private static final String TABLE_NAME = "qprofile_edit_users"; private static final String INDEX_NAME = "qprofile_edit_users_unique"; public DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/AddIndexOnUserUuidOfUserRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/AddIndexOnUserUuidOfUserRolesTable.java index 1ec8a5e88d7..c72ceb49d9a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/AddIndexOnUserUuidOfUserRolesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/AddIndexOnUserUuidOfUserRolesTable.java @@ -54,7 +54,7 @@ public class AddIndexOnUserUuidOfUserRolesTable extends DdlChange { private boolean indexExists() throws SQLException { try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); + return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection); } } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/DropIndexOnUserIdOfUserRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/DropIndexOnUserIdOfUserRolesTable.java index a8ad989b8f0..1746859b529 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/DropIndexOnUserIdOfUserRolesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/DropIndexOnUserIdOfUserRolesTable.java @@ -19,34 +19,14 @@ */ package org.sonar.server.platform.db.migration.version.v84.users.fk.userroles; -import java.sql.Connection; -import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.db.DatabaseUtils; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.step.DropIndexChange; -public class DropIndexOnUserIdOfUserRolesTable extends DdlChange { +public class DropIndexOnUserIdOfUserRolesTable extends DropIndexChange { private static final String TABLE_NAME = "user_roles"; private static final String INDEX_NAME = "user_roles_user"; public DropIndexOnUserIdOfUserRolesTable(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - if (indexExists()) { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName(INDEX_NAME) - .build()); - } - } - - private boolean indexExists() throws SQLException { - try (Connection connection = getDatabase().getDataSource().getConnection()) { - return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); - } + super(db, INDEX_NAME, TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ValidationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ValidationsTest.java index 57784591a77..8730060412c 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ValidationsTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ValidationsTest.java @@ -73,7 +73,7 @@ public class ValidationsTest { @Test public void validateIndexName_throws_NPE_when_index_name_is_null() { thrown.expect(NullPointerException.class); - thrown.expectMessage("Index name cannot be null"); + thrown.expectMessage("Index name can't be null"); validateIndexName(null); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java index 9371374dd67..a123ef9d69f 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java @@ -84,7 +84,7 @@ public class CreateIndexBuilderTest { @Test public void throw_NPE_if_table_is_missing() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Table name cannot be null"); + expectedException.expectMessage("Table name can't be null"); new CreateIndexBuilder() .setName("issues_key") @@ -95,7 +95,7 @@ public class CreateIndexBuilderTest { @Test public void throw_NPE_if_index_name_is_missing() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Index name cannot be null"); + expectedException.expectMessage("Index name can't be null"); new CreateIndexBuilder() .setTable("issues") diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderTest.java index d7ea93626d6..4b1274145ea 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderTest.java @@ -73,7 +73,7 @@ public class CreateTableBuilderTest { @Test public void constructor_fails_with_NPE_if_tablename_is_null() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Table name cannot be null"); + expectedException.expectMessage("Table name can't be null"); new CreateTableBuilder(mock(Dialect.class), null); } @@ -292,7 +292,7 @@ public class CreateTableBuilderTest { @Test public void withPkConstraintName_throws_NPE_if_name_is_null() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Constraint name cannot be null"); + expectedException.expectMessage("Constraint name can't be null"); underTest.withPkConstraintName(null); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilderTest.java index 4f9f7a7fa75..f26be6312a0 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilderTest.java @@ -55,7 +55,7 @@ public class DropIndexBuilderTest { @Test public void throw_NPE_if_table_name_is_missing() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Table name cannot be null"); + expectedException.expectMessage("Table name can't be null"); new DropIndexBuilder(new H2()) .setName("issues_key") @@ -76,7 +76,7 @@ public class DropIndexBuilderTest { @Test public void throw_NPE_if_index_name_is_missing() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Index name cannot be null"); + expectedException.expectMessage("Index name can't be null"); new DropIndexBuilder(new H2()) .setTable("issues") @@ -86,7 +86,7 @@ public class DropIndexBuilderTest { @Test public void throw_IAE_if_index_name_is_not_valid() { expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Index name must be lower case and contain only alphanumeric chars or '_', got '(not valid)'"); + expectedException.expectMessage("Index name must contain only alphanumeric chars or '_', got '(not valid)'"); new DropIndexBuilder(new H2()) .setTable("issues") -- 2.39.5