Add indexes

This commit is contained in:
James Agnew 2018-09-17 14:34:35 -04:00
parent efe2b8e93d
commit 125176cd75
2 changed files with 11 additions and 2 deletions

View File

@ -48,7 +48,7 @@ public class JdbcUtils {
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet indexes = metadata.getIndexInfo(null, null, theTableName, false, false);
ResultSet indexes = metadata.getIndexInfo(null, null, theTableName, false, true);
Set<String> indexNames = new HashSet<>();
while (indexes.next()) {

View File

@ -70,7 +70,16 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
String unique = myUnique ? "UNIQUE " : "";
String columns = String.join(", ", myColumns);
String sql = "CREATE " + unique + " INDEX " + myIndexName + " ON " + getTableName() + "(" + columns + ")";
executeSql(sql);
try {
executeSql(sql);
} catch (Exception e) {
if (e.toString().contains("already exists")) {
ourLog.warn("Index {} already exists", myIndexName);
} else {
throw e;
}
}
}
public void setColumns(String... theColumns) {