fixed bug in drop fk migration task

This commit is contained in:
Ken Stevens 2019-09-06 10:24:19 -04:00 committed by James Agnew
parent c88e6a6fa7
commit dded46d220
3 changed files with 10 additions and 10 deletions

View File

@ -34,14 +34,14 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
private static final Logger ourLog = LoggerFactory.getLogger(DropForeignKeyTask.class);
private String myConstraintName;
private String myForeignTableName;
private String myParentTableName;
public void setConstraintName(String theConstraintName) {
myConstraintName = theConstraintName;
}
public void setForeignTableName(String theForeignTableName) {
myForeignTableName = theForeignTableName;
public void setParentTableName(String theParentTableName) {
myParentTableName = theParentTableName;
}
@Override
@ -49,13 +49,13 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
super.validate();
Validate.isTrue(isNotBlank(myConstraintName));
Validate.isTrue(isNotBlank(myForeignTableName));
Validate.isTrue(isNotBlank(myParentTableName));
}
@Override
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)) {
ourLog.info("Don't have constraint named {} - No action performed", myConstraintName);
return;

View File

@ -249,13 +249,13 @@ public class BaseMigrationTasks<T extends Enum> {
/**
*
* @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();
task.setConstraintName(theFkName);
task.setForeignTableName(theForeignTableName);
task.setTableName(getTableName());
task.setParentTableName(theParentTableName);
addTask(task);
}

View File

@ -20,8 +20,8 @@ public class DropForeignKeyTaskTest extends BaseTest {
assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(1));
DropForeignKeyTask task = new DropForeignKeyTask();
task.setTableName("PARENT");
task.setForeignTableName("CHILD");
task.setTableName("CHILD");
task.setParentTableName("PARENT");
task.setConstraintName("FK_MOM");
getMigrator().addTask(task);