Merge pull request #1631 from jamesagnew/ks-20191213-oracle-migration

migration task don't compare length if no length is specified in the task
This commit is contained in:
Ken Stevens 2019-12-13 17:14:12 -05:00 committed by GitHub
commit d10ee1331f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 11 deletions

View File

@ -113,10 +113,10 @@ public class JdbcUtils {
return myLength;
}
public boolean equals(BaseTableColumnTypeTask.ColumnTypeEnum theColumnType, Long theColumnLength) {
return myColumnTypeEnum == theColumnType && (myLength == null || myLength.equals(theColumnLength));
public boolean equals(BaseTableColumnTypeTask.ColumnTypeEnum theTaskColumnType, Long theTaskColumnLength) {
ourLog.debug("Comparing existing {} {} to new {} {}", myColumnTypeEnum, myLength, theTaskColumnType, theTaskColumnLength);
return myColumnTypeEnum == theTaskColumnType && (theTaskColumnLength == null || theTaskColumnLength.equals(myLength));
}
}
/**
@ -244,6 +244,7 @@ public class JdbcUtils {
}
ourLog.debug("Unable to find column {} in table {}.", theColumnName, theTableName);
return null;
} catch (SQLException e) {

View File

@ -61,22 +61,22 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
throw new InternalErrorException(e);
}
Long columnLength = getColumnLength();
if (columnLength != null && isNoColumnShrink()) {
Long taskColumnLength = getColumnLength();
if (taskColumnLength != null && isNoColumnShrink()) {
long existingLength = existingType.getLength() != null ? existingType.getLength() : 0;
if (existingLength > columnLength) {
columnLength = existingLength;
if (existingLength > taskColumnLength) {
taskColumnLength = existingLength;
}
}
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), columnLength);
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), taskColumnLength);
boolean alreadyCorrectNullable = isNullable() == nullable;
if (alreadyOfCorrectType && alreadyCorrectNullable) {
logInfo(ourLog, "Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable);
return;
}
String type = getSqlType(columnLength);
String type = getSqlType(taskColumnLength);
String notNull = getSqlNotNull();
String sql = null;

View File

@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import org.flywaydb.core.internal.command.DbMigrate;
import org.junit.Test;
import org.springframework.dao.DataIntegrityViolationException;
import java.sql.SQLException;
@ -234,7 +233,7 @@ public class ModifyColumnTest extends BaseTest {
}
@Test
public void testFailureNotAllowed() throws SQLException {
public void testFailureNotAllowed() {
executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))");
executeSql("insert into SOMETABLE (TEXTCOL) values ('HELLO')");
@ -254,4 +253,20 @@ public class ModifyColumnTest extends BaseTest {
}
@Test
public void dontCompareLengthIfNoneSpecifiedInTask() throws SQLException {
executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))");
ModifyColumnTask task = new ModifyColumnTask("1", "1");
task.setTableName("SOMETABLE");
task.setColumnName("PID");
task.setColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
task.setNullable(true);
JdbcUtils.ColumnType existingColumnType = JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "PID");
assertEquals(BaseTableColumnTypeTask.ColumnTypeEnum.LONG, existingColumnType.getColumnTypeEnum());
assertEquals(19L, existingColumnType.getLength().longValue());
assertTrue(existingColumnType.equals(task.getColumnType(), task.getColumnLength()));
}
}