diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/BaseDB2Platform.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/BaseDB2Platform.java index 8b313d26d..2ef1488ac 100644 --- a/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/BaseDB2Platform.java +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/BaseDB2Platform.java @@ -36,6 +36,7 @@ public abstract class BaseDB2Platform extends DatabasePlatform { .addDataIntegrity("23502","23503","23504","23511","23512","23511","42917","23515") .build(); + historySupport = new DB2HistorySupport(); booleanDbType = Types.BOOLEAN; dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint", false)); dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false)); diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/DB2HistorySupport.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/DB2HistorySupport.java new file mode 100644 index 000000000..122f1b57c --- /dev/null +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/db2/DB2HistorySupport.java @@ -0,0 +1,30 @@ +package io.ebean.config.dbplatform.db2; + +import io.ebean.config.dbplatform.DbStandardHistorySupport; + +/** + * DB2 based history support. + */ +public class DB2HistorySupport extends DbStandardHistorySupport { + + @Override + public String getAsOfViewSuffix(String asOfViewSuffix) { + return " for system_time as of ?"; + } + + @Override + public String getVersionsBetweenSuffix(String asOfViewSuffix) { + return " for system_time between ? and ?"; + } + + @Override + public String getSysPeriodLower(String tableAlias, String sysPeriod) { + return tableAlias + "." + sysPeriod + "_start"; + } + + @Override + public String getSysPeriodUpper(String tableAlias, String sysPeriod) { + return tableAlias + "." + sysPeriod + "_end"; + } + +} diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java index cef2edc92..8d606abfa 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java @@ -759,6 +759,11 @@ public class BaseTableDdl implements TableDdl { // we will apply only type changes or notNull -> null transition boolean isNull = Boolean.FALSE.equals(alter.isNotnull()); boolean applyToHistory = alter.getType() != null || isNull; + boolean syncExact = platformDdl.getPlatform().isPlatform(Platform.DB2); + // DB2 needs exact sync for notnull/null + if (syncExact && alter.isNotnull() != null) { + applyToHistory = true; + } if (applyToHistory) { platformDdl.regenerateHistoryTriggers(writer, alter.getTableName()); if (alterHistoryTables) { @@ -768,7 +773,10 @@ public class BaseTableDdl implements TableDdl { // ignore default value (not needed on history tables) alterHistoryColumn.setCurrentType(alter.getCurrentType()); alterHistoryColumn.setType(alter.getType()); - if (isNull) { + if (syncExact) { + alterHistoryColumn.setCurrentNotnull(alter.isCurrentNotnull()); + alterHistoryColumn.setNotnull(alter.isNotnull()); + } else if (isNull) { // do transition from notNull to null alterHistoryColumn.setCurrentNotnull(Boolean.TRUE); alterHistoryColumn.setNotnull(Boolean.FALSE); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DB2Ddl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DB2Ddl.java index 1eae12035..c021cfdfc 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DB2Ddl.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DB2Ddl.java @@ -1,7 +1,14 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform; -import io.ebean.annotation.ConstraintMode; +import java.util.ArrayList; +import java.util.List; + import io.ebean.config.dbplatform.DatabasePlatform; +import io.ebean.util.StringHelper; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite; +import io.ebeaninternal.dbmigration.migration.Column; /** * DB2 platform specific DDL. @@ -12,12 +19,13 @@ public class DB2Ddl extends PlatformDdl { super(platform); this.dropTableIfExists = "drop table "; this.dropSequenceIfExists = "drop sequence "; - this.dropConstraintIfExists = "drop constraint"; - this.dropIndexIfExists = "drop index "; + this.dropConstraintIfExists = "NOT USED"; + this.dropIndexIfExists = "NOT USED"; this.identitySuffix = " generated by default as identity"; this.columnSetNull = "drop not null"; this.columnSetType = "set data type "; this.inlineUniqueWhenNullable = false; + this.historyDdl = new Db2HistoryDdl(); } @Override @@ -30,7 +38,7 @@ public class DB2Ddl extends PlatformDdl { throw new NullPointerException(); } StringBuilder sb = new StringBuilder("create unique index "); - sb.append(uqName).append(" on ").append(tableName).append('('); + sb.append(maxConstraintName(uqName)).append(" on ").append(tableName).append('('); for (int i = 0; i < columns.length; i++) { if (i > 0) { @@ -43,8 +51,143 @@ public class DB2Ddl extends PlatformDdl { } @Override - protected void appendForeignKeyOnUpdate(StringBuilder buffer, ConstraintMode mode) { - // do nothing, no on update clause for db2 + public void alterTableAddColumn(DdlWrite writer, String tableName, Column column, boolean onHistoryTable, String defaultValue) { + + String convertedType = convert(column.getType()); + DdlBuffer buffer = alterTable(writer, tableName).append(addColumn, column.getName()); + buffer.append(convertedType); + + // Add default value also to history table if it is not excluded + if (defaultValue != null) { + buffer.append(" default "); + buffer.append(defaultValue); + } + + if (isTrue(column.isNotnull())) { + buffer.appendWithSpace(columnNotNull); + } + // DB2 History table must match exact! + if (!onHistoryTable) { + // check constraints cannot be added in one statement for h2 + if (!StringHelper.isNull(column.getCheckConstraint())) { + String ddl = alterTableAddCheckConstraint(tableName, column.getCheckConstraintName(), column.getCheckConstraint()); + writer.applyPostAlter().appendStatement(ddl); + } + } + + } + @Override + public String alterTableDropForeignKey(String tableName, String fkName) { + return alterTableDropConstraint(tableName, fkName); + }; + + @Override + public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) { + return alterTableDropConstraint(tableName, uniqueConstraintName) + + "\n" + dropIndex(uniqueConstraintName, tableName); } + @Override + public String alterTableDropConstraint(String tableName, String constraintName) { + StringBuilder sb = new StringBuilder(300); + sb.append("delimiter $$\n") + .append("begin\n") + .append("if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = '") + .append(maxConstraintName(constraintName).toUpperCase()) + .append("' and tabname = '").append(lowerTableName(tableName).toUpperCase()).append("') then\n") + + .append(" prepare stmt from 'alter table ").append(lowerTableName(tableName)) + .append(" drop constraint ").append(maxConstraintName(constraintName)).append("';\n") + + .append(" execute stmt;\n") + .append("end if;\n") + .append("end$$"); + return sb.toString(); + + } + + @Override + public String dropIndex(String indexName, String tableName, boolean concurrent) { + StringBuilder sb = new StringBuilder(300); + sb.append("delimiter $$\n") + .append("begin\n") + .append("if exists (select indname from syscat.indexes where indschema = current_schema and indname = '") + .append(maxConstraintName(indexName).toUpperCase()).append("') then\n") + .append(" prepare stmt from 'drop index ").append(maxConstraintName(indexName)).append("';\n") + .append(" execute stmt;\n") + .append("end if;\n") + .append("end$$"); + return sb.toString(); + } + + @Override + public String dropSequence(String sequenceName) { + StringBuilder sb = new StringBuilder(300); + sb.append("delimiter $$\n"); + sb.append("begin\n"); + sb.append("if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = '") + .append(maxConstraintName(sequenceName).toUpperCase()).append("') then\n"); + sb.append(" prepare stmt from 'drop sequence ").append(maxConstraintName(sequenceName)).append("';\n"); + sb.append(" execute stmt;\n"); + sb.append("end if;\n"); + sb.append("end$$"); + return sb.toString(); + } + +@Override +protected DdlAlterTable alterTable(DdlWrite writer, String tableName) { + return writer.applyAlterTable(tableName, Db2AlterTableWrite::new); +}; + static class Db2AlterTableWrite extends BaseAlterTableWrite { + + public Db2AlterTableWrite(String tableName) { + super(tableName); + } + + @Override + protected List postProcessCommands(List cmds) { + List ret = new ArrayList<>(cmds.size() + 1); + boolean requiresReorg = false; + for (AlterCmd cmd : cmds) { + ret.add(cmd); + if (!requiresReorg && checkReorg(cmd)) { + requiresReorg = true; + } + } + if (requiresReorg) { + ret.add(newRawCommand("call sysproc.admin_cmd('reorg table " + tableName() + "')")); + } + return ret; + } + + /** + * 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: + *
    + *
  • DROP COLUMN + *
  • ALTER COLUMN SET NOT NULL + *
  • ALTER COLUMN DROP NOT NULL + *
  • ALTER COLUMN SET DATA TYPE, except in the following situations:
    + * Increasing the length of a VARCHAR or VARGRAPHIC column
    + * Decreasing the length of a VARCHAR or VARGRAPHIC column without truncating trailing blanks from existing data, when no indexes + * exist on the column + *
+ * + */ + private boolean checkReorg(AlterCmd cmd) { + switch (cmd.getOperation()) { + case "drop column": + return true; + case "alter column": + String alter = cmd.getAlternation(); + return alter.equals("set not null") + || alter.equals("drop not default") + || alter.startsWith("set data type"); // note: altering varchar length only is not detected here + default: + return false; + } + } + } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/Db2HistoryDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/Db2HistoryDdl.java new file mode 100644 index 000000000..f1409974d --- /dev/null +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/Db2HistoryDdl.java @@ -0,0 +1,138 @@ +package io.ebeaninternal.dbmigration.ddlgeneration.platform; + +import java.util.Collection; + +import io.ebean.config.DatabaseConfig; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer; +import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite; +import io.ebeaninternal.dbmigration.migration.AddHistoryTable; +import io.ebeaninternal.dbmigration.migration.DropHistoryTable; +import io.ebeaninternal.dbmigration.model.MColumn; +import io.ebeaninternal.dbmigration.model.MTable; + +/** + * DB2 History support. + * + * @author Roland Praml, FOCONIS AG + */ +public class Db2HistoryDdl implements PlatformHistoryDdl { + + private String systemPeriodStart; + private String systemPeriodEnd; + private String transactionId; + private PlatformDdl platformDdl; + private String historySuffix; + + @Override + public void configure(DatabaseConfig config, PlatformDdl platformDdl) { + this.systemPeriodStart = config.getAsOfSysPeriod() + "_start"; + this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end"; + this.transactionId = config.getAsOfSysPeriod() + "_txn"; // required for DB2 + this.platformDdl = platformDdl; + this.historySuffix = config.getHistoryTableSuffix(); + } + + @Override + public void createWithHistory(DdlWrite writer, MTable table) { + String tableName = table.getName(); + String historyTableName = tableName + historySuffix; + + DdlBuffer apply = writer.applyPostAlter(); + apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(historyTableName).append(" (").newLine(); + + // create history table + Collection cols = table.allColumns(); + for (MColumn column : cols) { + if (!column.isDraftOnly()) { + writeColumnDefinition(apply, column.getName(), column.getType(), column.isNotnull() || column.isPrimaryKey()); + apply.append(",").newLine(); + } + } + writeColumnDefinition(apply, systemPeriodStart, "timestamp(12)", true); + apply.append(",").newLine(); + writeColumnDefinition(apply, systemPeriodEnd, "timestamp(12)", true); + apply.append(",").newLine(); + writeColumnDefinition(apply, transactionId, "timestamp(12)", false); + apply.newLine().append(")").endOfStatement(); + + // enable system versioning + addSysPeriodColumns(writer, tableName); + enableSystemVersioning(apply, tableName); + platformDdl.alterTable(writer, tableName).setHistoryHandled(); + + // drop all: We do not drop columns here, as the whole table will be dropped + disableSystemVersioning(writer.dropAll(), tableName); + writer.dropAll().append("drop table ").append(historyTableName).endOfStatement(); + } + + void addSysPeriodColumns(DdlWrite writer, String baseTable) { + platformDdl.alterTableAddColumn(writer, baseTable, systemPeriodStart, "timestamp(12) not null generated always as row begin", null); + platformDdl.alterTableAddColumn(writer, baseTable, systemPeriodEnd, "timestamp(12) not null generated always as row end", null); + platformDdl.alterTableAddColumn(writer, baseTable, transactionId, "timestamp(12) generated always as transaction start id", null); + platformDdl.alterTable(writer, baseTable).append("add period system_time", null) + .append("(").append(systemPeriodStart).append(",").append(systemPeriodEnd).append(")"); + } + + @Override + public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) { + dropHistoryTable(writer, dropHistoryTable.getBaseTable(), dropHistoryTable.getBaseTable() + historySuffix); + } + + protected void dropHistoryTable(DdlWrite writer, String baseTable, String historyTable) { + disableSystemVersioning(writer.apply(), baseTable); + writer.apply().append("alter table ").append(baseTable).append(" drop period system_time").endOfStatement(); + + // drop the period & period columns + platformDdl.alterTableDropColumn(writer, baseTable, systemPeriodStart); + platformDdl.alterTableDropColumn(writer, baseTable, systemPeriodEnd); + platformDdl.alterTableDropColumn(writer, baseTable, transactionId); + + // drop the history table + writer.applyPostAlter().append("drop table ").append(historyTable).endOfStatement(); + } + + @Override + public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) { + MTable table = writer.getTable(addHistoryTable.getBaseTable()); + if (table == null) { + throw new IllegalStateException("MTable " + addHistoryTable.getBaseTable() + " not found in writer? (required for history DDL)"); + } + createWithHistory(writer, table); + } + + @Override + public boolean alterHistoryTables() { + return true; + } + + @Override + public void updateTriggers(DdlWrite writer, String tableName) { + DdlAlterTable alter = platformDdl.alterTable(writer, tableName); + MTable table = writer.getTable(tableName); + if (table.isWithHistory() && !alter.isHistoryHandled()) { + disableSystemVersioning(writer.apply(), tableName); + enableSystemVersioning(writer.applyPostAlter(), tableName); + alter.setHistoryHandled(); + } + } + + protected void writeColumnDefinition(DdlBuffer buffer, String columnName, String type, boolean isNotNull) { + + String platformType = platformDdl.convert(type); + buffer.append(" ").append(platformDdl.lowerColumnName(columnName)); + buffer.append(" ").append(platformType); + if (isNotNull) { + buffer.append(" not null"); + } + } + + public void disableSystemVersioning(DdlBuffer apply, String tableName) { + apply.append("alter table ").append(tableName).append(" drop versioning").endOfStatement(); + } + + public void enableSystemVersioning(DdlBuffer apply, String tableName) { + apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(tableName).append(historySuffix).endOfStatement(); + } + +} diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_AlterColumnTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_AlterColumnTest.java index c6d884c3a..c688a669a 100644 --- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_AlterColumnTest.java +++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_AlterColumnTest.java @@ -135,7 +135,8 @@ public class PlatformDdl_AlterColumnTest { softly.assertThat(sql).isEqualTo("-- apply alter tables\n" + "alter table mytab alter column acol set data type varchar(50);\n" + "alter table mytab alter column acol set default 'hi';\n" - + "alter table mytab alter column acol set not null;\n"); + + "alter table mytab alter column acol set not null;\n" + + "call sysproc.admin_cmd('reorg table mytab');\n"); // alter.setCurrentNotnull(Boolean.TRUE); @@ -213,7 +214,10 @@ public class PlatformDdl_AlterColumnTest { sql = alterColumn(db2Ddl, alter); softly.assertThat(sql).isEqualTo("-- apply alter tables\n" - + "alter table mytab alter column acol set data type varchar(20);\n"); + + "alter table mytab alter column acol set data type varchar(20);\n" + // Note, this reorg may be not necessary when only length attribute is alterd + // but this is currently not implemented. + + "call sysproc.admin_cmd('reorg table mytab');\n"); alter.setType("bigint"); sql = alterColumn(pgDdl, alter); @@ -271,7 +275,8 @@ public class PlatformDdl_AlterColumnTest { sql = alterColumn(db2Ddl, alter); softly.assertThat(sql).isEqualTo("-- apply alter tables\n" - + "alter table mytab alter column acol set not null;\n"); + + "alter table mytab alter column acol set not null;\n" + + "call sysproc.admin_cmd('reorg table mytab');\n"); } @@ -512,7 +517,7 @@ public class PlatformDdl_AlterColumnTest { softly.assertThat(alterFkey(oraDdl, null, null)).isEqualTo(""); softly.assertThat(alterFkey(sqlServerDdl, null, null)).isEqualTo(""); softly.assertThat(alterFkey(hanaDdl, null, null)).isEqualTo(" on delete restrict on update restrict"); - softly.assertThat(alterFkey(db2Ddl, null, null)).isEqualTo(" on delete restrict"); + softly.assertThat(alterFkey(db2Ddl, null, null)).isEqualTo(" on delete restrict on update restrict"); } @Test @@ -536,7 +541,7 @@ public class PlatformDdl_AlterColumnTest { .isEqualTo(" on delete restrict on update set null"); softly.assertThat(alterFkey(db2Ddl, "RESTRICT", "SET_NULL")) - .isEqualTo(" on delete restrict"); + .isEqualTo(" on delete restrict on update set null"); } @Test @@ -560,7 +565,7 @@ public class PlatformDdl_AlterColumnTest { .isEqualTo(" on delete set null on update restrict"); softly.assertThat(alterFkey(db2Ddl, "SET_NULL", "RESTRICT")) - .isEqualTo(" on delete set null"); + .isEqualTo(" on delete set null on update restrict"); } @Test @@ -584,7 +589,7 @@ public class PlatformDdl_AlterColumnTest { .isEqualTo(" on delete set default on update cascade"); softly.assertThat(alterFkey(db2Ddl, "SET_DEFAULT", "CASCADE")) - .isEqualTo(" on delete set default"); + .isEqualTo(" on delete set default on update cascade"); } private String alterColumn(PlatformDdl ddl, AlterColumn alterColumn) { diff --git a/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java b/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java index 7131e0a90..df309a65a 100644 --- a/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java +++ b/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java @@ -235,6 +235,9 @@ public class DbMigrationTest extends BaseTestCase { case SQLSERVER17: // these DBs are 'standard based' so they also do not support HistoryExclude case MARIADB: case HANA: + case DB2LUW: + case DB2FORI: // not yet tested + case DB2ZOS: // not yet tested assertThat(versions2.get(0).getDiff().toString()).as("using platform: %s, versions2:%s", server().platform(), versions2) .contains("testString=foo2,foo1") .contains("testString2=bar2,bar1"); diff --git a/ebean-test/src/test/java/org/tests/model/history/TestHistoryExclude.java b/ebean-test/src/test/java/org/tests/model/history/TestHistoryExclude.java index 512469c57..64a5c54a8 100644 --- a/ebean-test/src/test/java/org/tests/model/history/TestHistoryExclude.java +++ b/ebean-test/src/test/java/org/tests/model/history/TestHistoryExclude.java @@ -70,7 +70,7 @@ public class TestHistoryExclude extends BaseTestCase { linkFound.getDocs().size(); } - @IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH}) + @IgnorePlatform({Platform.ORACLE, Platform.COCKROACH}) @Test public void testAsOfThenLazy() { diff --git a/ebean-test/src/test/java/org/tests/model/history/TestHistoryInclude.java b/ebean-test/src/test/java/org/tests/model/history/TestHistoryInclude.java index d59579f03..f1122447b 100644 --- a/ebean-test/src/test/java/org/tests/model/history/TestHistoryInclude.java +++ b/ebean-test/src/test/java/org/tests/model/history/TestHistoryInclude.java @@ -37,7 +37,7 @@ public class TestHistoryInclude extends BaseTestCase { assertThat(linkFound.getDocs().size()).isEqualTo(2); } - @IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH}) + @IgnorePlatform({Platform.ORACLE, Platform.COCKROACH}) @Test public void testAsOfThenLazy() { diff --git a/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToMany.java b/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToMany.java index 07254f3b6..b5c0c43d4 100644 --- a/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToMany.java +++ b/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToMany.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class TestHistoryOneToMany extends BaseTestCase { - @IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH}) + @IgnorePlatform({Platform.ORACLE, Platform.COCKROACH}) @Test public void test() throws InterruptedException { diff --git a/ebean-test/src/test/java/org/tests/query/finder/TestCustomerFinder.java b/ebean-test/src/test/java/org/tests/query/finder/TestCustomerFinder.java index a69fc0f84..7903adb9c 100644 --- a/ebean-test/src/test/java/org/tests/query/finder/TestCustomerFinder.java +++ b/ebean-test/src/test/java/org/tests/query/finder/TestCustomerFinder.java @@ -3,6 +3,8 @@ package org.tests.query.finder; import io.ebean.BaseTestCase; import io.ebean.DB; import io.ebean.Transaction; +import io.ebean.annotation.IgnorePlatform; +import io.ebean.annotation.Platform; import io.ebean.meta.*; import io.ebean.test.LoggedSql; import org.junit.jupiter.api.Test; @@ -163,6 +165,7 @@ public class TestCustomerFinder extends BaseTestCase { } @Test + @IgnorePlatform(Platform.DB2) // no query plans yet, for DB2 public void test_finders_queryPlans() { ResetBasicData.reset(); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql index 7afc39559..cc23e8881 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql @@ -159,19 +159,83 @@ create table migtest_oto_master ( constraint pk_migtest_oto_master primary key (id) ); +-- apply alter tables +alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history2 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history3 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history3 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history3 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history3 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history4 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history4 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history4 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history4 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history5 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history5 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history5 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history5 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history6 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history6 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history6 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history6 add period system_time (sys_period_start,sys_period_end); -- apply post alter create unique index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) exclude null keys; create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) exclude null keys; +create table migtest_e_history2_history ( + id integer not null, + test_string varchar(255), + obsolete_string1 varchar(255), + obsolete_string2 varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +create table migtest_e_history3_history ( + id integer not null, + test_string varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +create table migtest_e_history4_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +create table migtest_e_history5_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +create table migtest_e_history6_history ( + id integer not null, + test_number1 integer, + test_number2 integer not null, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id); -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql index b459d8c09..298982766 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql @@ -1,14 +1,82 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest1; -drop index ix_migtest_e_basic_indextest5; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST1') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_user ( id integer generated by default as identity not null, @@ -42,9 +110,14 @@ insert into migtest_e_user (id) select distinct user_id from migtest_e_basic; -- NOTE: table has @History - special migration may be necessary update migtest_e_history2 set test_string = 'unknown' where test_string is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; +alter table migtest_e_history6 drop versioning; -- apply alter tables alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); @@ -60,17 +133,37 @@ alter table migtest_e_basic add column new_boolean_field smallint default 0 defa alter table migtest_e_basic add column new_boolean_field2 smallint default 0 default true not null; alter table migtest_e_basic add column progress integer default 0 not null; alter table migtest_e_basic add column new_integer integer default 42 not null; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history alter column test_string set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 alter column test_string set default 'unknown'; alter table migtest_e_history2 alter column test_string set not null; alter table migtest_e_history2 add column test_string2 varchar(255); alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null; alter table migtest_e_history2 add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history alter column test_string set not null; +alter table migtest_e_history2_history add column test_string2 varchar(255); +alter table migtest_e_history2_history add column test_string3 varchar(255) default 'unknown' not null; +alter table migtest_e_history2_history add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history4 alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history5 add column test_boolean smallint default 0 default false not null; +alter table migtest_e_history5_history add column test_boolean smallint default 0 default false not null; alter table migtest_e_history6 alter column test_number1 set default 42; alter table migtest_e_history6 alter column test_number1 set not null; alter table migtest_e_history6 alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 set not null; +alter table migtest_e_history6_history alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted smallint default 0 default false not null; alter table migtest_oto_child add column master_id bigint; -- apply post alter @@ -84,34 +177,47 @@ create unique index uq_migtest_e_basic_status_indextest1 on migtest_e_basic(stat create unique index uq_migtest_e_basic_name on migtest_e_basic(name) exclude null keys; create unique index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) exclude null keys; create unique index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) exclude null keys; +create table migtest_e_history_history ( + id integer not null, + test_string bigint, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history add versioning use history table migtest_e_history_history; comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m on migtest_mtm_c_migtest_mtm_m (migtest_mtm_m_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m on migtest_mtm_m_migtest_mtm_c (migtest_mtm_m_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c on migtest_mtm_m_migtest_mtm_c (migtest_mtm_c_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_phone_numbers_migtest_mtm_m_id on migtest_mtm_m_phone_numbers (migtest_mtm_m_id); -alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; -alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict; +alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict; create index ix_migtest_ckey_parent_assoc_id on migtest_ckey_parent (assoc_id); -alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict; +alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict on update restrict; -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict; -alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict; -alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict on update restrict; +alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict on update restrict; +alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3); create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.2__dropsFor_1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.2__dropsFor_1.1.sql index c7f896822..7f78aa9b3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.2__dropsFor_1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.2__dropsFor_1.1.sql @@ -1,11 +1,25 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history2 drop versioning; -- apply alter tables alter table migtest_e_basic drop column description_file; alter table migtest_e_basic drop column old_boolean; alter table migtest_e_basic drop column old_boolean2; alter table migtest_e_basic drop column eref_id; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 drop column obsolete_string1; alter table migtest_e_history2 drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column obsolete_string1; +alter table migtest_e_history2_history drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); -- apply post alter +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; drop table migtest_e_ref; -drop sequence migtest_e_ref_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_REF_SEQ') then + prepare stmt from 'drop sequence migtest_e_ref_seq'; + execute stmt; +end if; +end$$; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql index 7e64cc664..557ab8d29 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql @@ -1,21 +1,152 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent; -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id; -alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_description; -alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_name; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest3; -drop index ix_migtest_e_basic_indextest6; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_CKEY_DETAIL_PARENT' and tabname = 'MIGTEST_CKEY_DETAIL') then + prepare stmt from 'alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_ONE_ID' and tabname = 'MIGTEST_FK_NONE') then + prepare stmt from 'alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_VIA_JOIN_ONE_ID' and tabname = 'MIGTEST_FK_NONE_VIA_JOIN') then + prepare stmt from 'alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION') then + prepare stmt from 'drop index uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_E_BASIC_USER_ID' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1') then + prepare stmt from 'drop index uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_NAME' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_NAME') then + prepare stmt from 'drop index uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST3') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest3'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_ref ( id integer generated by default as identity not null, @@ -27,6 +158,10 @@ create table migtest_e_ref ( update migtest_e_basic set status2 = 'N' where status2 is null; update migtest_e_basic set user_id = 23 where user_id is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history6 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number2 = 7 where test_number2 is null; @@ -42,15 +177,26 @@ alter table migtest_e_basic add column description_file blob(64M); alter table migtest_e_basic add column old_boolean smallint default 0 default false not null; alter table migtest_e_basic add column old_boolean2 smallint default 0; alter table migtest_e_basic add column eref_id integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 alter column test_string drop default; alter table migtest_e_history2 alter column test_string drop not null; alter table migtest_e_history2 add column obsolete_string1 varchar(255); alter table migtest_e_history2 add column obsolete_string2 varchar(255); +alter table migtest_e_history2_history alter column test_string drop not null; +alter table migtest_e_history2_history add column obsolete_string1 varchar(255); +alter table migtest_e_history2_history add column obsolete_string2 varchar(255); alter table migtest_e_history4 alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history6 alter column test_number1 drop default; alter table migtest_e_history6 alter column test_number1 drop not null; alter table migtest_e_history6 alter column test_number2 set default 7; alter table migtest_e_history6 alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 drop not null; +alter table migtest_e_history6_history alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); -- apply post alter alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I')); @@ -60,11 +206,15 @@ create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.4__dropsFor_1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.4__dropsFor_1.3.sql index 43523ab64..5542a954f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.4__dropsFor_1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.4__dropsFor_1.3.sql @@ -1,22 +1,53 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history drop versioning; +alter table migtest_e_history drop period system_time; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history5 drop versioning; -- apply alter tables alter table migtest_ckey_detail drop column one_key; alter table migtest_ckey_detail drop column two_key; +call sysproc.admin_cmd('reorg table migtest_ckey_detail'); alter table migtest_ckey_parent drop column assoc_id; +call sysproc.admin_cmd('reorg table migtest_ckey_parent'); alter table migtest_e_basic drop column new_string_field; alter table migtest_e_basic drop column new_boolean_field; alter table migtest_e_basic drop column new_boolean_field2; alter table migtest_e_basic drop column progress; alter table migtest_e_basic drop column new_integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history drop column sys_period_start; +alter table migtest_e_history drop column sys_period_end; +alter table migtest_e_history drop column sys_period_txn; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 drop column test_string2; alter table migtest_e_history2 drop column test_string3; alter table migtest_e_history2 drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column test_string2; +alter table migtest_e_history2_history drop column test_string3; +alter table migtest_e_history2_history drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history5 drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5'); +alter table migtest_e_history5_history drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5_history'); alter table migtest_e_softdelete drop column deleted; +call sysproc.admin_cmd('reorg table migtest_e_softdelete'); alter table migtest_oto_child drop column master_id; +call sysproc.admin_cmd('reorg table migtest_oto_child'); -- apply post alter +drop table migtest_e_history_history; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; drop table migtest_e_user; -drop sequence migtest_e_user_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_USER_SEQ') then + prepare stmt from 'drop sequence migtest_e_user_seq'; + execute stmt; +end if; +end$$; drop table migtest_mtm_c_migtest_mtm_m; drop table migtest_mtm_m_migtest_mtm_c; drop table migtest_mtm_m_phone_numbers; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations index 85f2f8601..7b05091cd 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations @@ -1,7 +1,7 @@ -101990988, 1.0__initial.sql -1882152352, 1.1.sql --2081356955, 1.2__dropsFor_1.1.sql --1397487290, 1.3.sql --1610622815, 1.4__dropsFor_1.3.sql +-1173442860, 1.0__initial.sql +-504970252, 1.1.sql +364066694, 1.2__dropsFor_1.1.sql +-2046803765, 1.3.sql +-1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql index bfc570b84..cacec3063 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql @@ -159,19 +159,83 @@ create table migtest_oto_master ( constraint pk_migtest_oto_master primary key (id) ); +-- apply alter tables +alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history2 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history3 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history3 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history3 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history3 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history4 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history4 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history4 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history4 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history5 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history5 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history5 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history5 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history6 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history6 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history6 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history6 add period system_time (sys_period_start,sys_period_end); -- apply post alter -create unique index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) exclude null keys; -create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) exclude null keys; +create unique index uq_mgtst__b_4aybzy on migtest_e_basic(indextest2) exclude null keys; +create unique index uq_mgtst__b_4ayc02 on migtest_e_basic(indextest6) exclude null keys; +create table migtest_e_history2_history ( + id integer not null, + test_string varchar(255), + obsolete_string1 varchar(255), + obsolete_string2 varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +create table migtest_e_history3_history ( + id integer not null, + test_string varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +create table migtest_e_history4_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +create table migtest_e_history5_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +create table migtest_e_history6_history ( + id integer not null, + test_number1 integer, + test_number2 integer not null, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_mgtst__rf_nm unique (name); -- foreign keys and indices create index ix_mgtst_fk_mok1xj on migtest_fk_cascade (one_id); -alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; +alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; create index ix_mgtst_fk_c4p3mv on migtest_fk_set_null (one_id); -alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_mgtst__bsc_rf_d on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_mgtst__bsc_rf_d foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_mgtst__bsc_rf_d foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_mgtst__b_eu8csq on migtest_e_basic (indextest1); create index ix_mgtst__b_eu8csu on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql index 058fce09a..4f0ea1cf5 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql @@ -1,14 +1,82 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_fk_cascade drop constraint fk_mgtst_fk_65kf6l; -alter table migtest_fk_set_null drop constraint fk_mgtst_fk_wicx8x; -alter table migtest_e_basic drop constraint ck_mgtst__bsc_stts; -alter table migtest_e_basic drop constraint ck_mgtst__b_z543fg; -alter table migtest_e_basic drop constraint uq_mgtst__b_4aybzy; -alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc02; -alter table migtest_e_enum drop constraint ck_mgtst__n_773sok; -drop index ix_mgtst__b_eu8csq; -drop index ix_mgtst__b_eu8csu; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_65KF6L' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_mgtst_fk_65kf6l'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_WICX8X' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_mgtst_fk_wicx8x'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__BSC_STTS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_mgtst__bsc_stts'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__B_Z543FG' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_mgtst__b_z543fg'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_4AYBZY' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_4aybzy'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_4AYBZY') then + prepare stmt from 'drop index uq_mgtst__b_4aybzy'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_4AYC02' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc02'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_4AYC02') then + prepare stmt from 'drop index uq_mgtst__b_4ayc02'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__N_773SOK' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_mgtst__n_773sok'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MGTST__B_EU8CSQ') then + prepare stmt from 'drop index ix_mgtst__b_eu8csq'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MGTST__B_EU8CSU') then + prepare stmt from 'drop index ix_mgtst__b_eu8csu'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_user ( id integer generated by default as identity not null, @@ -42,9 +110,14 @@ insert into migtest_e_user (id) select distinct user_id from migtest_e_basic; -- NOTE: table has @History - special migration may be necessary update migtest_e_history2 set test_string = 'unknown' where test_string is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; +alter table migtest_e_history6 drop versioning; -- apply alter tables alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); @@ -60,58 +133,91 @@ alter table migtest_e_basic add column new_boolean_field boolean default true no alter table migtest_e_basic add column new_boolean_field2 boolean default true not null; alter table migtest_e_basic add column progress integer default 0 not null; alter table migtest_e_basic add column new_integer integer default 42 not null; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history alter column test_string set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 alter column test_string set default 'unknown'; alter table migtest_e_history2 alter column test_string set not null; alter table migtest_e_history2 add column test_string2 varchar(255); alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null; alter table migtest_e_history2 add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history alter column test_string set not null; +alter table migtest_e_history2_history add column test_string2 varchar(255); +alter table migtest_e_history2_history add column test_string3 varchar(255) default 'unknown' not null; +alter table migtest_e_history2_history add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history4 alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history5 add column test_boolean boolean default false not null; +alter table migtest_e_history5_history add column test_boolean boolean default false not null; alter table migtest_e_history6 alter column test_number1 set default 42; alter table migtest_e_history6 alter column test_number1 set not null; alter table migtest_e_history6 alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 set not null; +alter table migtest_e_history6_history alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; -- apply post alter alter table migtest_e_basic add constraint ck_mgtst__bsc_stts check ( status in ('N','A','I','?')); -create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys; +create unique index uq_mgtst__b_vs45xo on migtest_e_basic(description) exclude null keys; -- NOTE: table has @History - special migration may be necessary update migtest_e_basic set new_boolean_field = old_boolean; alter table migtest_e_basic add constraint ck_mgtst__b_l39g41 check ( progress in (0,1,2)); -create unique index uq_migtest_e_basic_status_indextest1 on migtest_e_basic(status,indextest1) exclude null keys; -create unique index uq_migtest_e_basic_name on migtest_e_basic(name) exclude null keys; -create unique index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) exclude null keys; -create unique index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) exclude null keys; +create unique index uq_mgtst__b_ucfcne on migtest_e_basic(status,indextest1) exclude null keys; +create unique index uq_mgtst__bsc_nm on migtest_e_basic(name) exclude null keys; +create unique index uq_mgtst__b_4ayc00 on migtest_e_basic(indextest4) exclude null keys; +create unique index uq_mgtst__b_4ayc01 on migtest_e_basic(indextest5) exclude null keys; +create table migtest_e_history_history ( + id integer not null, + test_string bigint, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history add versioning use history table migtest_e_history_history; comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices create index ix_mgtst_mt_3ug4ok on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mt_93awga foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mt_93awga foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_mgtst_mt_3ug4ou on migtest_mtm_c_migtest_mtm_m (migtest_mtm_m_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mt_93awgk foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mt_93awgk foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_mgtst_mt_b7nbcu on migtest_mtm_m_migtest_mtm_c (migtest_mtm_m_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_mgtst_mt_ggi34k foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_mgtst_mt_ggi34k foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_mgtst_mt_b7nbck on migtest_mtm_m_migtest_mtm_c (migtest_mtm_c_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_mgtst_mt_ggi34a foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_mgtst_mt_ggi34a foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_mgtst_mt_do9ma3 on migtest_mtm_m_phone_numbers (migtest_mtm_m_id); -alter table migtest_mtm_m_phone_numbers add constraint fk_mgtst_mt_s8neid foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_phone_numbers add constraint fk_mgtst_mt_s8neid foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; -alter table migtest_ckey_detail add constraint fk_mgtst_ck_e1qkb5 foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict; +alter table migtest_ckey_detail add constraint fk_mgtst_ck_e1qkb5 foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict; create index ix_mgtst_ck_x45o21 on migtest_ckey_parent (assoc_id); -alter table migtest_ckey_parent add constraint fk_mgtst_ck_da00mr foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict; +alter table migtest_ckey_parent add constraint fk_mgtst_ck_da00mr foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict on update restrict; -alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict; -alter table migtest_fk_none add constraint fk_mgtst_fk_nn_n_d foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_none_via_join add constraint fk_mgtst_fk_9tknzj foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_e_basic add constraint fk_mgtst__bsc_sr_d foreign key (user_id) references migtest_e_user (id) on delete restrict; -alter table migtest_oto_child add constraint fk_mgtst_t__csyl38 foreign key (master_id) references migtest_oto_master (id) on delete restrict; +alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict on update restrict; +alter table migtest_fk_none add constraint fk_mgtst_fk_nn_n_d foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_none_via_join add constraint fk_mgtst_fk_9tknzj foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_e_basic add constraint fk_mgtst__bsc_sr_d foreign key (user_id) references migtest_e_user (id) on delete restrict on update restrict; +alter table migtest_oto_child add constraint fk_mgtst_t__csyl38 foreign key (master_id) references migtest_oto_master (id) on delete restrict on update restrict; create index ix_mgtst__b_eu8css on migtest_e_basic (indextest3); create index ix_mgtst__b_eu8csv on migtest_e_basic (indextest6); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.2__dropsFor_1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.2__dropsFor_1.1.sql index c7f896822..7f78aa9b3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.2__dropsFor_1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.2__dropsFor_1.1.sql @@ -1,11 +1,25 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history2 drop versioning; -- apply alter tables alter table migtest_e_basic drop column description_file; alter table migtest_e_basic drop column old_boolean; alter table migtest_e_basic drop column old_boolean2; alter table migtest_e_basic drop column eref_id; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 drop column obsolete_string1; alter table migtest_e_history2 drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column obsolete_string1; +alter table migtest_e_history2_history drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); -- apply post alter +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; drop table migtest_e_ref; -drop sequence migtest_e_ref_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_REF_SEQ') then + prepare stmt from 'drop sequence migtest_e_ref_seq'; + execute stmt; +end if; +end$$; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql index 5adb11e10..4dc9a692d 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql @@ -1,21 +1,152 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_ckey_detail drop constraint fk_mgtst_ck_e1qkb5; -alter table migtest_fk_cascade drop constraint fk_mgtst_fk_65kf6l; -alter table migtest_fk_none drop constraint fk_mgtst_fk_nn_n_d; -alter table migtest_fk_none_via_join drop constraint fk_mgtst_fk_9tknzj; -alter table migtest_fk_set_null drop constraint fk_mgtst_fk_wicx8x; -alter table migtest_e_basic drop constraint ck_mgtst__bsc_stts; -alter table migtest_e_basic drop constraint ck_mgtst__b_z543fg; -alter table migtest_e_basic drop constraint uq_mgtst__b_vs45xo; -alter table migtest_e_basic drop constraint fk_mgtst__bsc_sr_d; -alter table migtest_e_basic drop constraint uq_mgtst__b_ucfcne; -alter table migtest_e_basic drop constraint uq_mgtst__bsc_nm; -alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc00; -alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc01; -alter table migtest_e_enum drop constraint ck_mgtst__n_773sok; -drop index ix_mgtst__b_eu8css; -drop index ix_mgtst__b_eu8csv; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_CK_E1QKB5' and tabname = 'MIGTEST_CKEY_DETAIL') then + prepare stmt from 'alter table migtest_ckey_detail drop constraint fk_mgtst_ck_e1qkb5'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_65KF6L' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_mgtst_fk_65kf6l'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_NN_N_D' and tabname = 'MIGTEST_FK_NONE') then + prepare stmt from 'alter table migtest_fk_none drop constraint fk_mgtst_fk_nn_n_d'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_9TKNZJ' and tabname = 'MIGTEST_FK_NONE_VIA_JOIN') then + prepare stmt from 'alter table migtest_fk_none_via_join drop constraint fk_mgtst_fk_9tknzj'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST_FK_WICX8X' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_mgtst_fk_wicx8x'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__BSC_STTS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_mgtst__bsc_stts'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__B_Z543FG' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_mgtst__b_z543fg'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_VS45XO' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_vs45xo'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_VS45XO') then + prepare stmt from 'drop index uq_mgtst__b_vs45xo'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MGTST__BSC_SR_D' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint fk_mgtst__bsc_sr_d'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_UCFCNE' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_ucfcne'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_UCFCNE') then + prepare stmt from 'drop index uq_mgtst__b_ucfcne'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__BSC_NM' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__bsc_nm'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__BSC_NM') then + prepare stmt from 'drop index uq_mgtst__bsc_nm'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_4AYC00' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc00'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_4AYC00') then + prepare stmt from 'drop index uq_mgtst__b_4ayc00'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MGTST__B_4AYC01' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc01'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MGTST__B_4AYC01') then + prepare stmt from 'drop index uq_mgtst__b_4ayc01'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MGTST__N_773SOK' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_mgtst__n_773sok'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MGTST__B_EU8CSS') then + prepare stmt from 'drop index ix_mgtst__b_eu8css'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MGTST__B_EU8CSV') then + prepare stmt from 'drop index ix_mgtst__b_eu8csv'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_ref ( id integer generated by default as identity not null, @@ -27,6 +158,10 @@ create table migtest_e_ref ( update migtest_e_basic set status2 = 'N' where status2 is null; update migtest_e_basic set user_id = 23 where user_id is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history6 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number2 = 7 where test_number2 is null; @@ -42,29 +177,44 @@ alter table migtest_e_basic add column description_file blob(64M); alter table migtest_e_basic add column old_boolean boolean default false not null; alter table migtest_e_basic add column old_boolean2 boolean; alter table migtest_e_basic add column eref_id integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 alter column test_string drop default; alter table migtest_e_history2 alter column test_string drop not null; alter table migtest_e_history2 add column obsolete_string1 varchar(255); alter table migtest_e_history2 add column obsolete_string2 varchar(255); +alter table migtest_e_history2_history alter column test_string drop not null; +alter table migtest_e_history2_history add column obsolete_string1 varchar(255); +alter table migtest_e_history2_history add column obsolete_string2 varchar(255); alter table migtest_e_history4 alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history6 alter column test_number1 drop default; alter table migtest_e_history6 alter column test_number1 drop not null; alter table migtest_e_history6 alter column test_number2 set default 7; alter table migtest_e_history6 alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 drop not null; +alter table migtest_e_history6_history alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); -- apply post alter alter table migtest_e_ref add constraint uq_mgtst__rf_nm unique (name); alter table migtest_e_basic add constraint ck_mgtst__bsc_stts check ( status in ('N','A','I')); alter table migtest_e_basic add constraint ck_mgtst__b_z543fg check ( status2 in ('N','A','I')); -create unique index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) exclude null keys; -create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) exclude null keys; +create unique index uq_mgtst__b_4aybzy on migtest_e_basic(indextest2) exclude null keys; +create unique index uq_mgtst__b_4ayc02 on migtest_e_basic(indextest6) exclude null keys; alter table migtest_e_enum add constraint ck_mgtst__n_773sok check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices -alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; -alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; +alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_mgtst__bsc_rf_d on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_mgtst__bsc_rf_d foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_mgtst__bsc_rf_d foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_mgtst__b_eu8csq on migtest_e_basic (indextest1); create index ix_mgtst__b_eu8csu on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.4__dropsFor_1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.4__dropsFor_1.3.sql index 43523ab64..5542a954f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.4__dropsFor_1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.4__dropsFor_1.3.sql @@ -1,22 +1,53 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history drop versioning; +alter table migtest_e_history drop period system_time; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history5 drop versioning; -- apply alter tables alter table migtest_ckey_detail drop column one_key; alter table migtest_ckey_detail drop column two_key; +call sysproc.admin_cmd('reorg table migtest_ckey_detail'); alter table migtest_ckey_parent drop column assoc_id; +call sysproc.admin_cmd('reorg table migtest_ckey_parent'); alter table migtest_e_basic drop column new_string_field; alter table migtest_e_basic drop column new_boolean_field; alter table migtest_e_basic drop column new_boolean_field2; alter table migtest_e_basic drop column progress; alter table migtest_e_basic drop column new_integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history drop column sys_period_start; +alter table migtest_e_history drop column sys_period_end; +alter table migtest_e_history drop column sys_period_txn; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 drop column test_string2; alter table migtest_e_history2 drop column test_string3; alter table migtest_e_history2 drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column test_string2; +alter table migtest_e_history2_history drop column test_string3; +alter table migtest_e_history2_history drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history5 drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5'); +alter table migtest_e_history5_history drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5_history'); alter table migtest_e_softdelete drop column deleted; +call sysproc.admin_cmd('reorg table migtest_e_softdelete'); alter table migtest_oto_child drop column master_id; +call sysproc.admin_cmd('reorg table migtest_oto_child'); -- apply post alter +drop table migtest_e_history_history; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; drop table migtest_e_user; -drop sequence migtest_e_user_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_USER_SEQ') then + prepare stmt from 'drop sequence migtest_e_user_seq'; + execute stmt; +end if; +end$$; drop table migtest_mtm_c_migtest_mtm_m; drop table migtest_mtm_m_migtest_mtm_c; drop table migtest_mtm_m_phone_numbers; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations index 58003092b..b3d6b8896 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations @@ -1,7 +1,7 @@ -1364985791, 1.0__initial.sql -1265418767, 1.1.sql --2081356955, 1.2__dropsFor_1.1.sql --46810481, 1.3.sql --1610622815, 1.4__dropsFor_1.3.sql +1034179507, 1.0__initial.sql +-1206845521, 1.1.sql +364066694, 1.2__dropsFor_1.1.sql +161683967, 1.3.sql +-1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql index 714ed5d30..d9e893947 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql @@ -159,19 +159,83 @@ create table migtest_oto_master ( constraint pk_migtest_oto_master primary key (id) ); +-- apply alter tables +alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history2 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history3 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history3 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history3 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history3 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history4 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history4 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history4 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history4 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history5 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history5 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history5 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history5 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history6 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history6 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history6 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history6 add period system_time (sys_period_start,sys_period_end); -- apply post alter create unique index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) exclude null keys; create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) exclude null keys; +create table migtest_e_history2_history ( + id integer not null, + test_string varchar(255), + obsolete_string1 varchar(255), + obsolete_string2 varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +create table migtest_e_history3_history ( + id integer not null, + test_string varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +create table migtest_e_history4_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +create table migtest_e_history5_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +create table migtest_e_history6_history ( + id integer not null, + test_number1 integer, + test_number2 integer not null, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id); -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql index 365d84144..77c49370e 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql @@ -1,14 +1,82 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest1; -drop index ix_migtest_e_basic_indextest5; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST1') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_user ( id integer generated by default as identity not null, @@ -42,9 +110,14 @@ insert into migtest_e_user (id) select distinct user_id from migtest_e_basic; -- NOTE: table has @History - special migration may be necessary update migtest_e_history2 set test_string = 'unknown' where test_string is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; +alter table migtest_e_history6 drop versioning; -- apply alter tables alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); @@ -60,17 +133,37 @@ alter table migtest_e_basic add column new_boolean_field boolean default true no alter table migtest_e_basic add column new_boolean_field2 boolean default true not null; alter table migtest_e_basic add column progress integer default 0 not null; alter table migtest_e_basic add column new_integer integer default 42 not null; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history alter column test_string set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 alter column test_string set default 'unknown'; alter table migtest_e_history2 alter column test_string set not null; alter table migtest_e_history2 add column test_string2 varchar(255); alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null; alter table migtest_e_history2 add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history alter column test_string set not null; +alter table migtest_e_history2_history add column test_string2 varchar(255); +alter table migtest_e_history2_history add column test_string3 varchar(255) default 'unknown' not null; +alter table migtest_e_history2_history add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history4 alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history5 add column test_boolean boolean default false not null; +alter table migtest_e_history5_history add column test_boolean boolean default false not null; alter table migtest_e_history6 alter column test_number1 set default 42; alter table migtest_e_history6 alter column test_number1 set not null; alter table migtest_e_history6 alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 set not null; +alter table migtest_e_history6_history alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; -- apply post alter @@ -84,34 +177,47 @@ create unique index uq_migtest_e_basic_status_indextest1 on migtest_e_basic(stat create unique index uq_migtest_e_basic_name on migtest_e_basic(name) exclude null keys; create unique index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) exclude null keys; create unique index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) exclude null keys; +create table migtest_e_history_history ( + id integer not null, + test_string bigint, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history add versioning use history table migtest_e_history_history; comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m on migtest_mtm_c_migtest_mtm_m (migtest_mtm_m_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m on migtest_mtm_m_migtest_mtm_c (migtest_mtm_m_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c on migtest_mtm_m_migtest_mtm_c (migtest_mtm_c_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_phone_numbers_migtest_mtm_m_id on migtest_mtm_m_phone_numbers (migtest_mtm_m_id); -alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; -alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict; +alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict; create index ix_migtest_ckey_parent_assoc_id on migtest_ckey_parent (assoc_id); -alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict; +alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict on update restrict; -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict; -alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict; -alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict on update restrict; +alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict on update restrict; +alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3); create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.2__dropsFor_1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.2__dropsFor_1.1.sql index c7f896822..7f78aa9b3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.2__dropsFor_1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.2__dropsFor_1.1.sql @@ -1,11 +1,25 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history2 drop versioning; -- apply alter tables alter table migtest_e_basic drop column description_file; alter table migtest_e_basic drop column old_boolean; alter table migtest_e_basic drop column old_boolean2; alter table migtest_e_basic drop column eref_id; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 drop column obsolete_string1; alter table migtest_e_history2 drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column obsolete_string1; +alter table migtest_e_history2_history drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); -- apply post alter +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; drop table migtest_e_ref; -drop sequence migtest_e_ref_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_REF_SEQ') then + prepare stmt from 'drop sequence migtest_e_ref_seq'; + execute stmt; +end if; +end$$; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql index 6c4433f9d..c0280ba4f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql @@ -1,21 +1,152 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent; -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id; -alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_description; -alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_name; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest3; -drop index ix_migtest_e_basic_indextest6; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_CKEY_DETAIL_PARENT' and tabname = 'MIGTEST_CKEY_DETAIL') then + prepare stmt from 'alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_ONE_ID' and tabname = 'MIGTEST_FK_NONE') then + prepare stmt from 'alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_VIA_JOIN_ONE_ID' and tabname = 'MIGTEST_FK_NONE_VIA_JOIN') then + prepare stmt from 'alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION') then + prepare stmt from 'drop index uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_E_BASIC_USER_ID' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1') then + prepare stmt from 'drop index uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_NAME' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_NAME') then + prepare stmt from 'drop index uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST3') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest3'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_ref ( id integer generated by default as identity not null, @@ -27,6 +158,10 @@ create table migtest_e_ref ( update migtest_e_basic set status2 = 'N' where status2 is null; update migtest_e_basic set user_id = 23 where user_id is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history6 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number2 = 7 where test_number2 is null; @@ -42,15 +177,26 @@ alter table migtest_e_basic add column description_file blob(64M); alter table migtest_e_basic add column old_boolean boolean default false not null; alter table migtest_e_basic add column old_boolean2 boolean; alter table migtest_e_basic add column eref_id integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 alter column test_string drop default; alter table migtest_e_history2 alter column test_string drop not null; alter table migtest_e_history2 add column obsolete_string1 varchar(255); alter table migtest_e_history2 add column obsolete_string2 varchar(255); +alter table migtest_e_history2_history alter column test_string drop not null; +alter table migtest_e_history2_history add column obsolete_string1 varchar(255); +alter table migtest_e_history2_history add column obsolete_string2 varchar(255); alter table migtest_e_history4 alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history6 alter column test_number1 drop default; alter table migtest_e_history6 alter column test_number1 drop not null; alter table migtest_e_history6 alter column test_number2 set default 7; alter table migtest_e_history6 alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 drop not null; +alter table migtest_e_history6_history alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); -- apply post alter alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I')); @@ -60,11 +206,15 @@ create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.4__dropsFor_1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.4__dropsFor_1.3.sql index 43523ab64..5542a954f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.4__dropsFor_1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.4__dropsFor_1.3.sql @@ -1,22 +1,53 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history drop versioning; +alter table migtest_e_history drop period system_time; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history5 drop versioning; -- apply alter tables alter table migtest_ckey_detail drop column one_key; alter table migtest_ckey_detail drop column two_key; +call sysproc.admin_cmd('reorg table migtest_ckey_detail'); alter table migtest_ckey_parent drop column assoc_id; +call sysproc.admin_cmd('reorg table migtest_ckey_parent'); alter table migtest_e_basic drop column new_string_field; alter table migtest_e_basic drop column new_boolean_field; alter table migtest_e_basic drop column new_boolean_field2; alter table migtest_e_basic drop column progress; alter table migtest_e_basic drop column new_integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history drop column sys_period_start; +alter table migtest_e_history drop column sys_period_end; +alter table migtest_e_history drop column sys_period_txn; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 drop column test_string2; alter table migtest_e_history2 drop column test_string3; alter table migtest_e_history2 drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column test_string2; +alter table migtest_e_history2_history drop column test_string3; +alter table migtest_e_history2_history drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history5 drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5'); +alter table migtest_e_history5_history drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5_history'); alter table migtest_e_softdelete drop column deleted; +call sysproc.admin_cmd('reorg table migtest_e_softdelete'); alter table migtest_oto_child drop column master_id; +call sysproc.admin_cmd('reorg table migtest_oto_child'); -- apply post alter +drop table migtest_e_history_history; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; drop table migtest_e_user; -drop sequence migtest_e_user_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_USER_SEQ') then + prepare stmt from 'drop sequence migtest_e_user_seq'; + execute stmt; +end if; +end$$; drop table migtest_mtm_c_migtest_mtm_m; drop table migtest_mtm_m_migtest_mtm_c; drop table migtest_mtm_m_phone_numbers; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations index 99b573f52..17aaf2093 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations @@ -1,7 +1,7 @@ -840828324, 1.0__initial.sql --1269751430, 1.1.sql --2081356955, 1.2__dropsFor_1.1.sql --998558087, 1.3.sql --1610622815, 1.4__dropsFor_1.3.sql +-1345631840, 1.0__initial.sql +2135835079, 1.1.sql +364066694, 1.2__dropsFor_1.1.sql +-1510901098, 1.3.sql +-1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql index 714ed5d30..d9e893947 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql @@ -159,19 +159,83 @@ create table migtest_oto_master ( constraint pk_migtest_oto_master primary key (id) ); +-- apply alter tables +alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history2 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history3 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history3 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history3 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history3 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history4 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history4 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history4 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history4 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history5 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history5 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history5 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history5 add period system_time (sys_period_start,sys_period_end); +alter table migtest_e_history6 add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history6 add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history6 add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history6 add period system_time (sys_period_start,sys_period_end); -- apply post alter create unique index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) exclude null keys; create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) exclude null keys; +create table migtest_e_history2_history ( + id integer not null, + test_string varchar(255), + obsolete_string1 varchar(255), + obsolete_string2 varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +create table migtest_e_history3_history ( + id integer not null, + test_string varchar(255), + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +create table migtest_e_history4_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +create table migtest_e_history5_history ( + id integer not null, + test_number integer, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +create table migtest_e_history6_history ( + id integer not null, + test_number1 integer, + test_number2 integer not null, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id); -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql index 365d84144..77c49370e 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql @@ -1,14 +1,82 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest1; -drop index ix_migtest_e_basic_indextest5; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST2') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST1') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_user ( id integer generated by default as identity not null, @@ -42,9 +110,14 @@ insert into migtest_e_user (id) select distinct user_id from migtest_e_basic; -- NOTE: table has @History - special migration may be necessary update migtest_e_history2 set test_string = 'unknown' where test_string is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; +alter table migtest_e_history6 drop versioning; -- apply alter tables alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); @@ -60,17 +133,37 @@ alter table migtest_e_basic add column new_boolean_field boolean default true no alter table migtest_e_basic add column new_boolean_field2 boolean default true not null; alter table migtest_e_basic add column progress integer default 0 not null; alter table migtest_e_basic add column new_integer integer default 42 not null; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history add column sys_period_start timestamp(12) not null generated always as row begin; +alter table migtest_e_history add column sys_period_end timestamp(12) not null generated always as row end; +alter table migtest_e_history add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table migtest_e_history add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history alter column test_string set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 alter column test_string set default 'unknown'; alter table migtest_e_history2 alter column test_string set not null; alter table migtest_e_history2 add column test_string2 varchar(255); alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null; alter table migtest_e_history2 add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history alter column test_string set not null; +alter table migtest_e_history2_history add column test_string2 varchar(255); +alter table migtest_e_history2_history add column test_string3 varchar(255) default 'unknown' not null; +alter table migtest_e_history2_history add column new_column varchar(20); +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history4 alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type bigint; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history5 add column test_boolean boolean default false not null; +alter table migtest_e_history5_history add column test_boolean boolean default false not null; alter table migtest_e_history6 alter column test_number1 set default 42; alter table migtest_e_history6 alter column test_number1 set not null; alter table migtest_e_history6 alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 set not null; +alter table migtest_e_history6_history alter column test_number2 drop not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; -- apply post alter @@ -84,34 +177,47 @@ create unique index uq_migtest_e_basic_status_indextest1 on migtest_e_basic(stat create unique index uq_migtest_e_basic_name on migtest_e_basic(name) exclude null keys; create unique index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) exclude null keys; create unique index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) exclude null keys; +create table migtest_e_history_history ( + id integer not null, + test_string bigint, + sys_period_start timestamp(12) not null, + sys_period_end timestamp(12) not null, + sys_period_txn timestamp(12) +); +alter table migtest_e_history add versioning use history table migtest_e_history_history; comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m on migtest_mtm_c_migtest_mtm_m (migtest_mtm_m_id); -alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m on migtest_mtm_m_migtest_mtm_c (migtest_mtm_m_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c on migtest_mtm_m_migtest_mtm_c (migtest_mtm_c_id); -alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict; +alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; create index ix_migtest_mtm_m_phone_numbers_migtest_mtm_m_id on migtest_mtm_m_phone_numbers (migtest_mtm_m_id); -alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict; +alter table migtest_mtm_m_phone_numbers add constraint fk_migtest_mtm_m_phone_numbers_migtest_mtm_m_id foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict; -alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict; +alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict; create index ix_migtest_ckey_parent_assoc_id on migtest_ckey_parent (assoc_id); -alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict; +alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict on update restrict; -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict; -alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict; -alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict; -alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict on update restrict; +alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict on update restrict; +alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3); create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.2__dropsFor_1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.2__dropsFor_1.1.sql index c7f896822..7f78aa9b3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.2__dropsFor_1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.2__dropsFor_1.1.sql @@ -1,11 +1,25 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history2 drop versioning; -- apply alter tables alter table migtest_e_basic drop column description_file; alter table migtest_e_basic drop column old_boolean; alter table migtest_e_basic drop column old_boolean2; alter table migtest_e_basic drop column eref_id; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 drop column obsolete_string1; alter table migtest_e_history2 drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column obsolete_string1; +alter table migtest_e_history2_history drop column obsolete_string2; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); -- apply post alter +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; drop table migtest_e_ref; -drop sequence migtest_e_ref_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_REF_SEQ') then + prepare stmt from 'drop sequence migtest_e_ref_seq'; + execute stmt; +end if; +end$$; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql index 6c4433f9d..c0280ba4f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql @@ -1,21 +1,152 @@ -- Migrationscripts for ebean unittest -- drop dependencies -alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent; -alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id; -alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id; -alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id; -alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status; -alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_description; -alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_name; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4; -alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5; -alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status; -drop index ix_migtest_e_basic_indextest3; -drop index ix_migtest_e_basic_indextest6; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_CKEY_DETAIL_PARENT' and tabname = 'MIGTEST_CKEY_DETAIL') then + prepare stmt from 'alter table migtest_ckey_detail drop constraint fk_migtest_ckey_detail_parent'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_CASCADE_ONE_ID' and tabname = 'MIGTEST_FK_CASCADE') then + prepare stmt from 'alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_ONE_ID' and tabname = 'MIGTEST_FK_NONE') then + prepare stmt from 'alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_NONE_VIA_JOIN_ONE_ID' and tabname = 'MIGTEST_FK_NONE_VIA_JOIN') then + prepare stmt from 'alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_FK_SET_NULL_ONE_ID' and tabname = 'MIGTEST_FK_SET_NULL') then + prepare stmt from 'alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_BASIC_STATUS2' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_DESCRIPTION') then + prepare stmt from 'drop index uq_migtest_e_basic_description'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'FK_MIGTEST_E_BASIC_USER_ID' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_STATUS_INDEXTEST1') then + prepare stmt from 'drop index uq_migtest_e_basic_status_indextest1'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_NAME' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_NAME') then + prepare stmt from 'drop index uq_migtest_e_basic_name'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST4') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest4'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5' and tabname = 'MIGTEST_E_BASIC') then + prepare stmt from 'alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$ +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'UQ_MIGTEST_E_BASIC_INDEXTEST5') then + prepare stmt from 'drop index uq_migtest_e_basic_indextest5'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = 'CK_MIGTEST_E_ENUM_TEST_STATUS' and tabname = 'MIGTEST_E_ENUM') then + prepare stmt from 'alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST3') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest3'; + execute stmt; +end if; +end$$; +delimiter $$ +begin +if exists (select indname from syscat.indexes where indschema = current_schema and indname = 'IX_MIGTEST_E_BASIC_INDEXTEST6') then + prepare stmt from 'drop index ix_migtest_e_basic_indextest6'; + execute stmt; +end if; +end$$; -- apply changes create table migtest_e_ref ( id integer generated by default as identity not null, @@ -27,6 +158,10 @@ create table migtest_e_ref ( update migtest_e_basic set status2 = 'N' where status2 is null; update migtest_e_basic set user_id = 23 where user_id is null; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history3 drop versioning; +alter table migtest_e_history4 drop versioning; +alter table migtest_e_history6 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number2 = 7 where test_number2 is null; @@ -42,15 +177,26 @@ alter table migtest_e_basic add column description_file blob(64M); alter table migtest_e_basic add column old_boolean boolean default false not null; alter table migtest_e_basic add column old_boolean2 boolean; alter table migtest_e_basic add column eref_id integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); alter table migtest_e_history2 alter column test_string drop default; alter table migtest_e_history2 alter column test_string drop not null; alter table migtest_e_history2 add column obsolete_string1 varchar(255); alter table migtest_e_history2 add column obsolete_string2 varchar(255); +alter table migtest_e_history2_history alter column test_string drop not null; +alter table migtest_e_history2_history add column obsolete_string1 varchar(255); +alter table migtest_e_history2_history add column obsolete_string2 varchar(255); alter table migtest_e_history4 alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4'); +alter table migtest_e_history4_history alter column test_number set data type integer; +call sysproc.admin_cmd('reorg table migtest_e_history4_history'); alter table migtest_e_history6 alter column test_number1 drop default; alter table migtest_e_history6 alter column test_number1 drop not null; alter table migtest_e_history6 alter column test_number2 set default 7; alter table migtest_e_history6 alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6'); +alter table migtest_e_history6_history alter column test_number1 drop not null; +alter table migtest_e_history6_history alter column test_number2 set not null; +call sysproc.admin_cmd('reorg table migtest_e_history6_history'); -- apply post alter alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I')); @@ -60,11 +206,15 @@ create unique index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; +alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; +alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; -- foreign keys and indices -alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; -alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; +alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; +alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); -alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict; +alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.4__dropsFor_1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.4__dropsFor_1.3.sql index 43523ab64..5542a954f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.4__dropsFor_1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.4__dropsFor_1.3.sql @@ -1,22 +1,53 @@ -- Migrationscripts for ebean unittest +-- apply changes +alter table migtest_e_history drop versioning; +alter table migtest_e_history drop period system_time; +alter table migtest_e_history2 drop versioning; +alter table migtest_e_history5 drop versioning; -- apply alter tables alter table migtest_ckey_detail drop column one_key; alter table migtest_ckey_detail drop column two_key; +call sysproc.admin_cmd('reorg table migtest_ckey_detail'); alter table migtest_ckey_parent drop column assoc_id; +call sysproc.admin_cmd('reorg table migtest_ckey_parent'); alter table migtest_e_basic drop column new_string_field; alter table migtest_e_basic drop column new_boolean_field; alter table migtest_e_basic drop column new_boolean_field2; alter table migtest_e_basic drop column progress; alter table migtest_e_basic drop column new_integer; +call sysproc.admin_cmd('reorg table migtest_e_basic'); +alter table migtest_e_history drop column sys_period_start; +alter table migtest_e_history drop column sys_period_end; +alter table migtest_e_history drop column sys_period_txn; +call sysproc.admin_cmd('reorg table migtest_e_history'); alter table migtest_e_history2 drop column test_string2; alter table migtest_e_history2 drop column test_string3; alter table migtest_e_history2 drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2'); +alter table migtest_e_history2_history drop column test_string2; +alter table migtest_e_history2_history drop column test_string3; +alter table migtest_e_history2_history drop column new_column; +call sysproc.admin_cmd('reorg table migtest_e_history2_history'); alter table migtest_e_history5 drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5'); +alter table migtest_e_history5_history drop column test_boolean; +call sysproc.admin_cmd('reorg table migtest_e_history5_history'); alter table migtest_e_softdelete drop column deleted; +call sysproc.admin_cmd('reorg table migtest_e_softdelete'); alter table migtest_oto_child drop column master_id; +call sysproc.admin_cmd('reorg table migtest_oto_child'); -- apply post alter +drop table migtest_e_history_history; +alter table migtest_e_history2 add versioning use history table migtest_e_history2_history; +alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; drop table migtest_e_user; -drop sequence migtest_e_user_seq; +delimiter $$ +begin +if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = 'MIGTEST_E_USER_SEQ') then + prepare stmt from 'drop sequence migtest_e_user_seq'; + execute stmt; +end if; +end$$; drop table migtest_mtm_c_migtest_mtm_m; drop table migtest_mtm_m_migtest_mtm_c; drop table migtest_mtm_m_phone_numbers; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations index 99b573f52..17aaf2093 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations @@ -1,7 +1,7 @@ -840828324, 1.0__initial.sql --1269751430, 1.1.sql --2081356955, 1.2__dropsFor_1.1.sql --998558087, 1.3.sql --1610622815, 1.4__dropsFor_1.3.sql +-1345631840, 1.0__initial.sql +2135835079, 1.1.sql +364066694, 1.2__dropsFor_1.1.sql +-1510901098, 1.3.sql +-1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql