]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13594 Upgrade to 8.4 fails on MS SQL Server
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 7 Jul 2020 17:13:36 +0000 (12:13 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 10 Jul 2020 20:05:50 +0000 (20:05 +0000)
55 files changed:
server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java
server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/just_one_table.sql [deleted file]
server/sonar-db-core/src/test/resources/org/sonar/db/DatabaseUtilsTest/sql.sql [new file with mode: 0644]
server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreDbTester.java
server/sonar-db-core/src/testFixtures/java/org/sonar/db/CoreTestDb.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/Validations.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexChange.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/AddIndexOnSlugOfProjectAlmSettings.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropIndexOnActiveRuleIdOfActiveRuleParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddTechIndexOnUuidOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropTechIndexOnUuidOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/AddIndexToActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/AddIndexesToRulesParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropUniqueIndexOnKeeColumnOfRulesProfilesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/AddUniqueIndexOnProfileUuidColumnOfActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/fk/activerules/DropUniqueIndexOnProfileIdColumnOfActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropUniqueIndexOnUuidColumnOfUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddIndexOnUserUuidOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropIndexOnUserIdOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/groupsusers/DropUniqueIndexOnUserIdAndGroupIdOfGroupsUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddIndexOnUserUuidOfOrganizationMembersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropIndexOnUserIdOfOrganizationMembersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/qprofileeditusers/DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/AddIndexOnUserUuidOfUserRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/userroles/DropIndexOnUserIdOfUserRolesTable.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ValidationsTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropIndexBuilderTest.java

index fff31a948244be3967dcf76cbc585a8dca9a1092..ff53e51f5d81d0af1b31641e8fb1f4a9a1311e85 100644 (file)
@@ -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<String> findExistingIndex(Connection connection, String tableName, String indexName) {
+    Optional<String> 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<String> 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);
     }
   }
 
index 383133974c51cd84e18d1b9fb9387b5f8adfc724..7342a0a47c54c666c908c8b7ed1a9bee5a9bd631 100644 (file)
@@ -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 (file)
index a101905..0000000
+++ /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 (file)
index 0000000..ec4b878
--- /dev/null
@@ -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);
index f55338c174a078c93c911787d914711163ad5385..c4c14117b8254d63ddcebc6210c3c2ab7e4c22c0 100644 (file)
@@ -34,9 +34,13 @@ public class CoreDbTester extends AbstractDbTester<CoreTestDb> {
   }
 
   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() {
index 56d6821f9f7c736f74fe6a3538e23412446f25d2..c1c5c0dfdf8f2b575a04352cf476116c2808de88 100644 (file)
@@ -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<Settings> noExtraSettingsLoaded = settings -> {
     };
     Function<Settings, Database> 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<Database> databaseInitializer = database -> {
       if (schemaPath == null) {
index fb9abe2a901fdbdf1f07f7f058572483be0df7d3..b09eb4ad51a9ac85d76fd2a17ac75948ae02bfea 100644 (file)
@@ -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);
+  }
 }
index 1d77ba7864aa4dab16200b94ce31d5366694f6f1..936340783b9e72095ed6064e8e50a30de3c99c0d 100644 (file)
  */
 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<String> 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 (file)
index 0000000..0fd7345
--- /dev/null
@@ -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<String> indexName = findExistingIndexName();
+    indexName.ifPresent(index -> context.execute(new DropIndexBuilder(getDialect())
+      .setTable(tableName)
+      .setName(index)
+      .build()));
+  }
+
+  private Optional<String> findExistingIndexName() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.findExistingIndex(connection, tableName, indexName);
+    }
+  }
+}
index 974a0eb69d9b7e592658bcfb0181d0f8f8bfe413..6349e4bd62a4e1cc8cac08728e8006208d383157 100644 (file)
@@ -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);
     }
   }
 
index 26bfea0a4f3c0dceef4e6e885f5a3e58f8a245af..9d4cabeeef7cbdb2fb0b8b1ee803f40008bcae07 100644 (file)
@@ -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);
     }
   }
 }
index b8df35a9fe7125f26fc9ec9440a48cb8cbc41749..ddc4b1a0387f99a240257947b689fa05ce0ba166 100644 (file)
  */
 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);
   }
 }
index 5f898380b2f7703f9c0a042787a8ee2d809b6489..f3665469759b59e746e790c26d5097bbe18d9a55 100644 (file)
  */
 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());
-  }
-
 }
index d7d994638372d10cd81be1f733be69a2ee28ae50..e60e5079529e20c9d7b771610d5153bf842f20b2 100644 (file)
@@ -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);
     }
   }
 }
index 93f6dbe721602158162a4874f36c8efd89fb173f..005de5c9c3aa081f2307cac252362bdcc53c522e 100644 (file)
  */
 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);
   }
 }
index ecb0f5d36bcbdc128bb6c7de112c979d27be9b89..6f6c7930a616da9a089e107de67fe8fa782327f4 100644 (file)
@@ -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);
     }
   }
 }
index 3b01f284cd05522fe732c62451de0d1ca90c9700..a087126ff2745e9be52f12769211b1079ef5bccb 100644 (file)
@@ -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<String> 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<String> 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);
     }
   }
 }
index 2029b8b249930cbe53cdb5ae9aa9c88fd7c059b0..9d5989e6a855edc624676603f53cbefeba17450e 100644 (file)
@@ -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);
     }
   }
 }
index d64275b6a6a854b1eed2c7c8a0e94addb81da1b9..9cccc40f55416785f2195548fc6ac44dae637684 100644 (file)
  */
 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);
   }
 }
index 9e39b935d508de5a9c46f316d3937d7c3dc60c85..268c8400ccd532be12e41fa63c816e2f286a07ef 100644 (file)
@@ -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);
     }
   }
 }
index 56cb5019ae116c8b4f84e0b5e17815af623fcbe3..93e5234f4658c6808a1f19e9b2e4dc31cba98f9e 100644 (file)
@@ -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);
     }
   }
 }
index d92a46e3df0aca0652f346de6e0ed2830c9c2420..9537d32cefeda3a832048bfe7409f7c555d9f17f 100644 (file)
@@ -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);
     }
   }
 }
index 0a257945a07983cf2b6bab502dfbf35ba1d34abe..86b29fb8bba7f2f3319b3f97ff8bdb9b9b55bbe7 100644 (file)
@@ -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);
     }
   }
 }
index 8f6b8f37404c60afe47b49e7ed517cb2155c8c1a..f9f70153a0da12b5223db83d58a1492f90047012 100644 (file)
@@ -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);
     }
   }
 }
index 7c63295791736ed969fab19371e283c6598be135..338f4f57bb225a3ac89c9a947e5d69d496f0e07d 100644 (file)
  */
 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);
   }
 }
index e1797a97ea34e01cd99eb6423763a5ccedb965b2..939e0840c3524aeca0387dc618222593c2e9c0aa 100644 (file)
  */
 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);
   }
 }
index 9e4a37657d15353a6dc040b805b55345c1f1524d..1e34df9a06311cb594ae460c8d2ff6887c518fdc 100644 (file)
@@ -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);
     }
   }
 }
index e1d0705c1aad21de5d0a397689defe699cde6227..33503ec947a13e15f3338157a140c41ada456a21 100644 (file)
  */
 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);
-    }
-  }
 }
index 6e51337ef03dbc9b51e713bc939848e4ccb128b7..cfbb48c8ac41e5dd420cabeae4d10b55fffc7734 100644 (file)
  */
 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);
   }
 }
index 021c54c9f753f20d9ec286f59c024a8c62084249..bb052873e157a9f6fcb815d59d9f5c121f337f6d 100644 (file)
@@ -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);
     }
   }
 
index 0ba65c96767ebf4113283146446b5e1cecc7b97d..d993272acd01d85c5d3da48632101453ba2c05b6 100644 (file)
  */
 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());
-  }
-
 }
index b15ecfc3ade12f2b189a16af455a0e13fce20fd6..f998365c3fd023c9acd06cd2cd39f115ac9acabd 100644 (file)
@@ -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);
     }
   }
 
index 9aea9da32cfbb29d13257c600d4ceab8f33c9e31..8ec1dab354c18a41b25325b2a5e2780e0995614b 100644 (file)
  */
 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());
-  }
-
 }
index f0f8aa59a2f742df99d78c84df7035aafe2d3d25..81e8fb1c8ead59ea801a79c9336627e177e78c35 100644 (file)
@@ -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);
     }
   }
 }
index ea2e66feb50c1c7517677523c8231eea7598050f..c6f29480148343e88e4e221491cb16e5c9a31a33 100644 (file)
@@ -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);
     }
   }
 
index 9d2d4667d946b75fba984a5e0a6eecde9ddf8e4e..ed1402f884981bd192876ef15647272efdfd9b86 100644 (file)
  */
 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<String> 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<String> findExistingIndexName(String indexName) throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.findExistingIndex(connection, TABLE_NAME, indexName);
+    }
+  }
 }
index ca55e835a2ba3f0141ac1baed169cfa9daa96524..70640deaa658c1c9440d90f89d76e5cfaf5606e4 100644 (file)
  */
 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);
   }
 }
index 8c856cd86e18acaa8ae15bda19aba9653b187483..6bb024790edd0114ada8193a8776999a32f5d862 100644 (file)
@@ -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);
     }
   }
 }
index 7241cfe4b192d82a884f0d8bc216b1fecf74ecb5..0d1e570d1c2a7760276f395c40aecf42571625c2 100644 (file)
  */
 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);
   }
 }
index 0e5ba8d20c26ac111e33a9aa9febe27fffdf2e37..8c277cd871bdb077fc736c79acb252706bf971fe 100644 (file)
  */
 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);
   }
 }
index 3a47ef732008a656d07b44cd7e94a17f479b8ee7..2af95ce64879c99ce9f00533f1488f67d89a1a9f 100644 (file)
@@ -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);
     }
   }
 }
index 0c9179c5dc67c083a52f4354534e1cdcd870e043..0facd88fbf82e8b9b75977f7f8d19b3bde492ede 100644 (file)
@@ -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);
     }
   }
 }
index 4df0d1b7de665d501d6cc628cba89be698c8af35..abad87f06acb3af3d58a886df89e60a13772c4c9 100644 (file)
  */
 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);
   }
 }
index 7afb9cd4d5151b1375eceeed354ba11c3af05c55..0822650a4d2e5f9e345fb60e047e2ef22ea5f2b7 100644 (file)
  */
 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);
-    }
-  }
 }
index 21fb387e9e5a12d8111dbf1ab0ada0bfbe08b925..9010f8fd65cea9bcfd8b25dd7fb3b756f025e8e5 100644 (file)
@@ -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);
     }
   }
 }
index 90b8196a1b7e759afb6c9eaadf432f94966fc70a..9fc81b4713339d91bf357fc094c3f5ab09cb956b 100644 (file)
  */
 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);
   }
 }
index 38eb2e8f97389be89a8c95698832e92ba3341857..8dd7f371ce002efccc785e92b1d3cc0528ddbbd7 100644 (file)
@@ -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);
     }
   }
 }
index eafca322d16928eb84a13eea03f6df3983368377..82afc9ba268f2b3a43620bbf2729ec0b92747a81 100644 (file)
  */
 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);
   }
 }
index 1ec8a5e88d734bf1efe30b8d82ace02fbb1b7f3f..c72ceb49d9a5497ebca8789348500d23b86f1e14 100644 (file)
@@ -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);
     }
   }
 }
index a8ad989b8f0a0e5cbaef05e1e2e2fd7b55bcf3f6..1746859b529cbca6b1de272a5b53067482bb4308 100644 (file)
  */
 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);
   }
 }
index 57784591a77a7df5c43da2e0ff6dccf8d778fb42..8730060412cbcdc6d93b140978acde2e44ec1b88 100644 (file)
@@ -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);
   }
index 9371374dd670ca30f6ab95d24abab1ffd5f3f8f1..a123ef9d69faf52722dca6f463f287c9633c219b 100644 (file)
@@ -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")
index d7ea93626d673b103ca28e6f39b93fef15522337..4b1274145ea17c464122d5a5d2a88b12eb322700 100644 (file)
@@ -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);
   }
index 4f9f7a7fa75be71d26ee6a52b469a49d2fd39d1e..f26be6312a0d7205d721a1fc0598afbecfb71922 100644 (file)
@@ -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")