Merge pull request #2064 from jamesagnew/fix_mssql_drop_index_and_table_migrations

Fix mssql drop index and table migrations
This commit is contained in:
michelgleeson 2020-09-03 12:29:04 -04:00 committed by GitHub
commit 7ad89294f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View File

@ -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();

View File

@ -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<String> indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName());

View File

@ -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<String> 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());