fixed npe
This commit is contained in:
parent
f6fc411407
commit
945cc6419f
|
@ -52,7 +52,7 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
|
|||
throw new InternalErrorException(e);
|
||||
}
|
||||
|
||||
if (isNoColumnShrink()) {
|
||||
if (getColumnLength() != null && isNoColumnShrink()) {
|
||||
long existingLength = existingType.getLength() != null ? existingType.getLength() : 0;
|
||||
if (existingLength > getColumnLength()) {
|
||||
setColumnLength(existingLength);
|
||||
|
|
|
@ -98,6 +98,45 @@ public class ModifyColumnTest extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoShrink_ColumnMakeDateNullable() throws SQLException {
|
||||
executeSql("create table SOMETABLE (PID bigint not null, DATECOL timestamp not null)");
|
||||
assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "PID"));
|
||||
assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "DATECOL"));
|
||||
assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG, 19), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "PID"));
|
||||
assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP, 26), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "DATECOL"));
|
||||
|
||||
getMigrator().setNoColumnShrink(true);
|
||||
|
||||
// PID
|
||||
ModifyColumnTask task = new ModifyColumnTask();
|
||||
task.setTableName("SOMETABLE");
|
||||
task.setColumnName("PID");
|
||||
task.setColumnType(AddColumnTask.ColumnTypeEnum.LONG);
|
||||
task.setNullable(true);
|
||||
getMigrator().addTask(task);
|
||||
|
||||
// STRING
|
||||
task = new ModifyColumnTask();
|
||||
task.setTableName("SOMETABLE");
|
||||
task.setColumnName("DATECOL");
|
||||
task.setColumnType(AddColumnTask.ColumnTypeEnum.DATE_TIMESTAMP);
|
||||
task.setNullable(true);
|
||||
getMigrator().addTask(task);
|
||||
|
||||
// Do migration
|
||||
getMigrator().migrate();
|
||||
|
||||
assertTrue(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "PID"));
|
||||
assertTrue(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "DATECOL"));
|
||||
assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG, 19), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "PID"));
|
||||
assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP, 26), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "DATECOL"));
|
||||
|
||||
// Make sure additional migrations don't crash
|
||||
getMigrator().migrate();
|
||||
getMigrator().migrate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnMakeNotNullable() throws SQLException {
|
||||
executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))");
|
||||
|
|
Loading…
Reference in New Issue