diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java index e47787244a8..d7d430f746c 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java @@ -60,6 +60,14 @@ public abstract class BaseTask { mySchemaVersion = theSchemaVersion; } + public String getProductVersion() { + return myProductVersion; + } + + public String getSchemaVersion() { + return mySchemaVersion; + } + public boolean isNoColumnShrink() { return myNoColumnShrink; } @@ -137,16 +145,18 @@ public abstract class BaseTask { return myConnectionProperties; } - public void setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) { + public BaseTask setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) { myConnectionProperties = theConnectionProperties; + return this; } public DriverTypeEnum getDriverType() { return myDriverType; } - public void setDriverType(DriverTypeEnum theDriverType) { + public BaseTask setDriverType(DriverTypeEnum theDriverType) { myDriverType = theDriverType; + return this; } public abstract void validate(); 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 2e04e4416a6..c04f6e22672 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 @@ -86,9 +86,13 @@ public class DropIndexTask extends BaseTableTask { @Language("SQL") String findConstraintSql = "SELECT DISTINCT constraint_name FROM user_cons_columns WHERE constraint_name = ? AND table_name = ?"; @Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?"; findAndDropConstraint(findConstraintSql, dropConstraintSql); - findConstraintSql = "SELECT DISTINCT constraint_name FROM all_constraints WHERE index_name = ? AND table_name = ?"; findAndDropConstraint(findConstraintSql, dropConstraintSql); + } else if (getDriverType() == DriverTypeEnum.MSSQL_2012) { + // Legacy deletion for SQL Server unique indexes + @Language("SQL") String findConstraintSql = "SELECT tc.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc WHERE tc.CONSTRAINT_NAME = ? AND tc.TABLE_NAME = ?"; + @Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?"; + findAndDropConstraint(findConstraintSql, dropConstraintSql); } Set indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName()); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java index 3d9eb3b4fcf..3f2bf48f0f2 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java @@ -63,14 +63,15 @@ public class DropTableTask extends BaseTableTask { } } + DropIndexTask theIndexTask = new DropIndexTask(getProductVersion(), getSchemaVersion()); + theIndexTask + .setTableName(getTableName()) + .setConnectionProperties(getConnectionProperties()) + .setDriverType(getDriverType()); for (String nextIndex : indexNames) { - List sqls = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType()); - if (!sqls.isEmpty()) { - logInfo(ourLog, "Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName()); - } - for (@Language("SQL") String sql : sqls) { - executeSql(getTableName(), sql); - } + theIndexTask + .setIndexName(nextIndex) + .execute(); } logInfo(ourLog, "Dropping table: {}", getTableName());