#374 - Drop foreign keys before indexes

This commit is contained in:
Robin Bygrave
2015-08-06 13:37:51 +12:00
parent 8cde0da419
commit 93f802f7fe
5 changed files with 31 additions and 13 deletions
@@ -254,7 +254,7 @@ public class DdlGenerator implements SpiEbeanPlugin {
stmt = stmt.substring(0, stmt.length() - 1);
}
logger.trace("executing " + oneOf + " " + getSummary(stmt));
logger.info("executing " + oneOf + " " + getSummary(stmt));
pstmt = c.prepareStatement(stmt);
pstmt.execute();
@@ -215,17 +215,16 @@ public class BaseTableDdl implements TableDdl {
fkeyBuffer.end();
write.rollbackForeignKeys()
.append(platformDdl.alterTableDropForeignKey(tableName, fkName))
.endOfStatement();
if (addIndex) {
write.rollbackForeignKeys()
.append("drop index ").append(indexName)
.append(platformDdl.dropIndex(indexName, tableName))
.endOfStatement();
}
write.rollbackForeignKeys()
.append("alter table ").append(tableName).append(" ")
.append(platformDdl.dropForeignKeyConstraint(fkName))
.endOfStatement();
write.rollbackForeignKeys().end();
}
@@ -13,9 +13,19 @@ public class MySqlDdl extends PlatformDdl {
this.namingConvention.maxConstraintNameLength = 64;
}
/**
* Return the drop index statement.
*/
@Override
public String dropForeignKeyConstraint(String fkName) {
return "drop foreign key " + fkName;
public String dropIndex(String indexName, String tableName) {
return "drop index " + indexName + " on " + tableName;
}
/**
* Return the drop foreign key clause.
*/
public String alterTableDropForeignKey(String tableName, String fkName) {
return "alter table " + tableName + " drop foreign key " + fkName;
}
}
@@ -79,8 +79,8 @@ public class PlatformDdl {
/**
* Return the drop foreign key clause.
*/
public String dropForeignKeyConstraint(String fkName) {
return "drop constraint "+fkName;
public String alterTableDropForeignKey(String tableName, String fkName) {
return "alter table " + tableName + " drop constraint " + fkName;
}
/**
@@ -131,6 +131,13 @@ public class PlatformDdl {
return dropTableIfExists + tableName + dropTableCascade;
}
/**
* Return the drop index statement.
*/
public String dropIndex(String indexName, String tableName) {
return "drop index "+indexName;
}
/**
* Support lower naming tables and columns in DDL generation.
* Tables/Columns with quoted identifiers are exempt.
@@ -148,4 +155,6 @@ public class PlatformDdl {
public int getMaxTableNameLength() {
return namingConvention.getMaxTableNameLength();
}
}