FIX DB2 migration: reorg table must be called after drop not null

This commit is contained in:
Noemi Praml
2022-09-02 10:49:25 +02:00
parent a5c3bbb97e
commit fbb73d465c
4 changed files with 24 additions and 5 deletions
@@ -39,12 +39,12 @@ public class DB2Ddl extends PlatformDdl {
return String.format(MOVE_TABLE, tablename.toUpperCase(), tableSpace, indexSpace, lobSpace);
}
}
@Override
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
if (nullableColumns == null || nullableColumns.length == 0) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
}
}
if (uqName == null) {
throw new NullPointerException();
@@ -66,7 +66,7 @@ public class DB2Ddl extends PlatformDdl {
public void addTablespace(DdlBuffer apply, String tablespaceName, String indexTablespace, String lobTablespace) {
apply.append(" in ").append(tablespaceName).append(" index in ").append(indexTablespace).append(" long in ").append(lobTablespace);
}
@Override
public void alterTableAddColumn(DdlWrite writer, String tableName, Column column, boolean onHistoryTable, String defaultValue) {
@@ -209,7 +209,7 @@ public class DB2Ddl extends PlatformDdl {
/**
* determine, if we need a reorg.
*
*
* See: https://www.ibm.com/docs/en/db2/11.5?topic=statements-alter-table The following is the full list of REORG-recommended
* ALTER statements that cause a version change and place the table into a REORG-pending state:
* <ul>
@@ -221,7 +221,7 @@ public class DB2Ddl extends PlatformDdl {
* Decreasing the length of a VARCHAR or VARGRAPHIC column without truncating trailing blanks from existing data, when no indexes
* exist on the column
* </ul>
*
*
*/
private boolean checkReorg(AlterCmd cmd) {
switch (cmd.getOperation()) {
@@ -230,6 +230,7 @@ public class DB2Ddl extends PlatformDdl {
case "alter column":
String alter = cmd.getAlternation();
return alter.equals("set not null")
|| alter.equals("drop not null")
|| alter.equals("drop not default")
|| alter.startsWith("set data type"); // note: altering varchar length only is not detected here
default:
@@ -293,6 +293,7 @@ public class DbMigrationTest extends BaseTestCase {
table.setFrom("foo");
table.setTo("bar");
table.setIndex("id");
table.setTextfield("test");
tmpServer.save(table);
table = tmpServer.find(ETable.class).where().eq("index", "id").findOne();
assert table != null;
@@ -3,6 +3,7 @@ package misc.migration.v1_0;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
import io.ebean.annotation.NotNull;
import javax.persistence.*;
import java.util.List;
@@ -36,6 +37,17 @@ public class ETable {
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
@NotNull
private String textfield;
public void setTextfield(String textfield) {
this.textfield = textfield;
}
public String getTextfield() {
return textfield;
}
public String getIndex() {
return index;
}
@@ -39,4 +39,9 @@ public class ETable {
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
private String textfield;
@Index
private String textfield2;
}