diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java index 10c10ace63e..989494806b2 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java @@ -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 indexNames = new HashSet<>(); while (indexes.next()) { diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java index db16792ba3d..f5e40556901 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java @@ -70,7 +70,16 @@ public class AddIndexTask extends BaseTableTask { 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) {