diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1994-fix-mssql-errors.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1994-fix-mssql-errors.yaml new file mode 100644 index 00000000000..b366bca0fe4 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1994-fix-mssql-errors.yaml @@ -0,0 +1,4 @@ +--- +type: add +issue: 1994 +title: "A few issues in the migrator when applying migrations against some versions of MSSQL were resolved" 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 cd4b3305fb9..c47cc2cd64b 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 @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.migrate.taskdef; * #L% */ +import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -78,7 +79,18 @@ public class AddIndexTask extends BaseTableTask { String unique = myUnique ? "unique " : ""; String columns = String.join(", ", myColumns); - String sql = "create " + unique + "index " + myIndexName + " on " + getTableName() + "(" + columns + ")"; + String mssqlWhereClause = ""; + if (myUnique && getDriverType() == DriverTypeEnum.MSSQL_2012) { + mssqlWhereClause = " WHERE ("; + for (int i = 0; i foreignKeys = JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), getColumnName(), getTableName()); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java index 9d5b3171f3b..ae15fa6c8a7 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java @@ -116,9 +116,11 @@ public class DropIndexTask extends BaseTableTask { break; case DERBY_EMBEDDED: case ORACLE_12C: - case MSSQL_2012: sql.add("alter table " + theTableName + " drop constraint " + theIndexName); break; + case MSSQL_2012: + sql.add("drop index " + theIndexName + " on " + theTableName); + break; case POSTGRES_9_4: sql.add("alter table " + theTableName + " drop constraint if exists " + theIndexName + " cascade"); sql.add("drop index if exists " + theIndexName + " cascade");