fixed bug in drop fk migration task
This commit is contained in:
parent
c88e6a6fa7
commit
dded46d220
|
@ -34,14 +34,14 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(DropForeignKeyTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(DropForeignKeyTask.class);
|
||||||
private String myConstraintName;
|
private String myConstraintName;
|
||||||
private String myForeignTableName;
|
private String myParentTableName;
|
||||||
|
|
||||||
public void setConstraintName(String theConstraintName) {
|
public void setConstraintName(String theConstraintName) {
|
||||||
myConstraintName = theConstraintName;
|
myConstraintName = theConstraintName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForeignTableName(String theForeignTableName) {
|
public void setParentTableName(String theParentTableName) {
|
||||||
myForeignTableName = theForeignTableName;
|
myParentTableName = theParentTableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,13 +49,13 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
|
||||||
super.validate();
|
super.validate();
|
||||||
|
|
||||||
Validate.isTrue(isNotBlank(myConstraintName));
|
Validate.isTrue(isNotBlank(myConstraintName));
|
||||||
Validate.isTrue(isNotBlank(myForeignTableName));
|
Validate.isTrue(isNotBlank(myParentTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws SQLException {
|
public void execute() throws SQLException {
|
||||||
|
|
||||||
Set<String> existing = JdbcUtils.getForeignKeys(getConnectionProperties(), getTableName(), myForeignTableName);
|
Set<String> existing = JdbcUtils.getForeignKeys(getConnectionProperties(), myParentTableName, getTableName());
|
||||||
if (!existing.contains(myConstraintName)) {
|
if (!existing.contains(myConstraintName)) {
|
||||||
ourLog.info("Don't have constraint named {} - No action performed", myConstraintName);
|
ourLog.info("Don't have constraint named {} - No action performed", myConstraintName);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -249,13 +249,13 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param theFkName the name of the foreign key
|
* @param theFkName the name of the foreign key
|
||||||
* @param theForeignTableName the name of the table that imports the foreign key (I know it's a confusing name, but that's what java.sql.DatabaseMetaData calls it)
|
* @param theParentTableName the name of the table that exports the foreign key
|
||||||
*/
|
*/
|
||||||
public void dropForeignKey(String theFkName, String theForeignTableName) {
|
public void dropForeignKey(String theFkName, String theParentTableName) {
|
||||||
DropForeignKeyTask task = new DropForeignKeyTask();
|
DropForeignKeyTask task = new DropForeignKeyTask();
|
||||||
task.setConstraintName(theFkName);
|
task.setConstraintName(theFkName);
|
||||||
task.setForeignTableName(theForeignTableName);
|
|
||||||
task.setTableName(getTableName());
|
task.setTableName(getTableName());
|
||||||
|
task.setParentTableName(theParentTableName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ public class DropForeignKeyTaskTest extends BaseTest {
|
||||||
assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(1));
|
assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(1));
|
||||||
|
|
||||||
DropForeignKeyTask task = new DropForeignKeyTask();
|
DropForeignKeyTask task = new DropForeignKeyTask();
|
||||||
task.setTableName("PARENT");
|
task.setTableName("CHILD");
|
||||||
task.setForeignTableName("CHILD");
|
task.setParentTableName("PARENT");
|
||||||
task.setConstraintName("FK_MOM");
|
task.setConstraintName("FK_MOM");
|
||||||
getMigrator().addTask(task);
|
getMigrator().addTask(task);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue