Skip ModifyColumn migration tasks for columns that don't exist
This commit is contained in:
parent
c04f1d15d8
commit
a839a645db
|
@ -26,6 +26,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask> {
|
public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask> {
|
||||||
|
|
||||||
|
@ -33,10 +34,17 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() throws SQLException {
|
||||||
|
|
||||||
String existingType;
|
String existingType;
|
||||||
boolean nullable;
|
boolean nullable;
|
||||||
|
|
||||||
|
Set<String> columnNames = JdbcUtils.getColumnNames(getConnectionProperties(), getTableName());
|
||||||
|
if (!columnNames.contains(getColumnName())) {
|
||||||
|
ourLog.info("Column {} doesn't exist on table {} - No action performed", getColumnName(), getTableName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
existingType = JdbcUtils.getColumnType(getConnectionProperties(), getTableName(), getColumnName());
|
existingType = JdbcUtils.getColumnType(getConnectionProperties(), getTableName(), getColumnName());
|
||||||
nullable = JdbcUtils.isColumnNullable(getConnectionProperties(), getTableName(), getColumnName());
|
nullable = JdbcUtils.isColumnNullable(getConnectionProperties(), getTableName(), getColumnName());
|
||||||
|
@ -115,5 +123,4 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
|
||||||
executeSql(getTableName(), sqlNotNull);
|
executeSql(getTableName(), sqlNotNull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class ModifyColumnTest extends BaseTest {
|
public class ModifyColumnTest extends BaseTest {
|
||||||
|
@ -111,4 +112,20 @@ public class ModifyColumnTest extends BaseTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testColumnDoesntAlreadyExist() throws SQLException {
|
||||||
|
executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))");
|
||||||
|
|
||||||
|
ModifyColumnTask task = new ModifyColumnTask();
|
||||||
|
task.setTableName("SOMETABLE");
|
||||||
|
task.setColumnName("SOMECOLUMN");
|
||||||
|
task.setDescription("Make nullable");
|
||||||
|
task.setNullable(true);
|
||||||
|
getMigrator().addTask(task);
|
||||||
|
|
||||||
|
getMigrator().migrate();
|
||||||
|
|
||||||
|
assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue