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:
commit
7ad89294f7
|
@ -60,6 +60,14 @@ public abstract class BaseTask {
|
||||||
mySchemaVersion = theSchemaVersion;
|
mySchemaVersion = theSchemaVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProductVersion() {
|
||||||
|
return myProductVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchemaVersion() {
|
||||||
|
return mySchemaVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isNoColumnShrink() {
|
public boolean isNoColumnShrink() {
|
||||||
return myNoColumnShrink;
|
return myNoColumnShrink;
|
||||||
}
|
}
|
||||||
|
@ -137,16 +145,18 @@ public abstract class BaseTask {
|
||||||
return myConnectionProperties;
|
return myConnectionProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) {
|
public BaseTask setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) {
|
||||||
myConnectionProperties = theConnectionProperties;
|
myConnectionProperties = theConnectionProperties;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DriverTypeEnum getDriverType() {
|
public DriverTypeEnum getDriverType() {
|
||||||
return myDriverType;
|
return myDriverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDriverType(DriverTypeEnum theDriverType) {
|
public BaseTask setDriverType(DriverTypeEnum theDriverType) {
|
||||||
myDriverType = theDriverType;
|
myDriverType = theDriverType;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void validate();
|
public abstract void validate();
|
||||||
|
|
|
@ -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 findConstraintSql = "SELECT DISTINCT constraint_name FROM user_cons_columns WHERE constraint_name = ? AND table_name = ?";
|
||||||
@Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?";
|
@Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?";
|
||||||
findAndDropConstraint(findConstraintSql, dropConstraintSql);
|
findAndDropConstraint(findConstraintSql, dropConstraintSql);
|
||||||
|
|
||||||
findConstraintSql = "SELECT DISTINCT constraint_name FROM all_constraints WHERE index_name = ? AND table_name = ?";
|
findConstraintSql = "SELECT DISTINCT constraint_name FROM all_constraints WHERE index_name = ? AND table_name = ?";
|
||||||
findAndDropConstraint(findConstraintSql, dropConstraintSql);
|
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());
|
Set<String> indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName());
|
||||||
|
|
|
@ -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) {
|
for (String nextIndex : indexNames) {
|
||||||
List<String> sqls = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType());
|
theIndexTask
|
||||||
if (!sqls.isEmpty()) {
|
.setIndexName(nextIndex)
|
||||||
logInfo(ourLog, "Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName());
|
.execute();
|
||||||
}
|
|
||||||
for (@Language("SQL") String sql : sqls) {
|
|
||||||
executeSql(getTableName(), sql);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo(ourLog, "Dropping table: {}", getTableName());
|
logInfo(ourLog, "Dropping table: {}", getTableName());
|
||||||
|
|
Loading…
Reference in New Issue