Dont fail on shrink only task
This commit is contained in:
parent
b794618e9d
commit
97ac551c87
|
@ -173,6 +173,11 @@ public abstract class BaseTask {
|
|||
myFailureAllowed = theFailureAllowed;
|
||||
}
|
||||
|
||||
protected boolean isFailureAllowed() {
|
||||
return myFailureAllowed;
|
||||
}
|
||||
|
||||
|
||||
public String getFlywayVersion() {
|
||||
String releasePart = myProductVersion;
|
||||
if (releasePart.startsWith("V")) {
|
||||
|
|
|
@ -62,10 +62,17 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask {
|
|||
}
|
||||
|
||||
Long taskColumnLength = getColumnLength();
|
||||
if (taskColumnLength != null && isNoColumnShrink()) {
|
||||
boolean isShrinkOnly = false;
|
||||
if (taskColumnLength != null) {
|
||||
long existingLength = existingType.getLength() != null ? existingType.getLength() : 0;
|
||||
if (existingLength > taskColumnLength) {
|
||||
taskColumnLength = existingLength;
|
||||
if (isNoColumnShrink()) {
|
||||
taskColumnLength = existingLength;
|
||||
} else {
|
||||
if (existingType.getColumnTypeEnum() == getColumnType()) {
|
||||
isShrinkOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,6 +136,10 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask {
|
|||
throw new IllegalStateException("Dont know how to handle " + getDriverType());
|
||||
}
|
||||
|
||||
if (!isFailureAllowed() && isShrinkOnly) {
|
||||
setFailureAllowed(true);
|
||||
}
|
||||
|
||||
logInfo(ourLog, "Updating column {} on table {} to type {}", getColumnName(), getTableName(), type);
|
||||
if (sql != null) {
|
||||
executeSql(getTableName(), sql);
|
||||
|
@ -139,4 +150,5 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask {
|
|||
executeSql(getTableName(), sqlNotNull);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,4 +269,29 @@ public class ModifyColumnTest extends BaseTest {
|
|||
assertTrue(existingColumnType.equals(task.getColumnType(), task.getColumnLength()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testShrinkDoesntFailIfShrinkCannotProceed() throws SQLException {
|
||||
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(10))");
|
||||
executeSql("insert into SOMETABLE (PID, TEXTCOL) values (1, '0123456789')");
|
||||
|
||||
ModifyColumnTask task = new ModifyColumnTask("1", "123456.7");
|
||||
task.setTableName("SOMETABLE");
|
||||
task.setColumnName("TEXTCOL");
|
||||
task.setColumnType(AddColumnTask.ColumnTypeEnum.STRING);
|
||||
task.setNullable(true);
|
||||
task.setColumnLength(5);
|
||||
|
||||
getMigrator().addTask(task);
|
||||
getMigrator().migrate();
|
||||
|
||||
assertEquals(1, task.getExecutedStatements().size());
|
||||
assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 10), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "TEXTCOL"));
|
||||
|
||||
// Make sure additional migrations don't crash
|
||||
getMigrator().migrate();
|
||||
getMigrator().migrate();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue