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;
}
/**
- * @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) ||
}
}
- 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);
}
}
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;
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
@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);
assertThat(isClosed(statement)).isTrue();
assertThat(isClosed(rs)).isTrue();
- } finally {
- DatabaseUtils.closeQuietly(connection);
}
}
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) {
},
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
+++ /dev/null
-CREATE TABLE "SCHEMA_MIGRATIONS" (
- "VERSION" VARCHAR(256) NOT NULL
-);
--- /dev/null
+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);
}
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() {
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;
}
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 -> {
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) {
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() {
* @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;
}
* @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;
}
* @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.
*
* @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;
}
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);
+ }
}
*/
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;
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 {
public List<String> build() {
validateTableName(tableName);
- validateIndexName(indexName);
+ validateIndexNameIgnoreCase(indexName);
return singletonList(createSqlStatement());
}
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);
- }
- }
}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
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);
}
}
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);
}
}
}
*/
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);
}
}
*/
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());
- }
-
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
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;
@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);
}
}
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
*/
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);
- }
- }
}
*/
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);
}
}
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);
}
}
*/
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());
- }
-
}
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);
}
}
*/
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());
- }
-
}
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);
}
}
}
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);
}
}
*/
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);
@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);
+ }
+ }
}
*/
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);
}
}
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);
}
}
}
*/
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);
}
}
*/
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);
}
}
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);
}
}
}
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);
}
}
}
*/
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);
}
}
*/
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);
- }
- }
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
*/
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);
}
}
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);
}
}
}
*/
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);
}
}
@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);
}
@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")
@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")
@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);
}
@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);
}
@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")
@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")
@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")