mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#374 - Drop foreign keys before indexes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user