pk) {
return namingConvention.getSequenceName(createTable.getName(), pk.get(0).getName());
}
@@ -288,6 +292,19 @@ public class BaseTableDdl implements TableDdl {
}
}
+ /**
+ * Add tablespace declaration.
+ */
+ protected void addTableTableSpaces(DdlBuffer apply, CreateTable createTable) {
+ String tableSpace = platformDdl.extract(createTable.getTablespace());
+ if (hasValue(tableSpace)) {
+ platformDdl.addTablespace(apply,
+ tableSpace,
+ platformDdl.extract(createTable.getIndexTablespace()),
+ platformDdl.extract(createTable.getLobTablespace()));
+ }
+ }
+
/**
* Add the table storage engine clause.
*/
@@ -647,6 +664,25 @@ public class BaseTableDdl implements TableDdl {
}
}
+ /**
+ * Add table related changes to DDL (tableSpace,...)
+ */
+ @Override
+ public void generate(DdlWrite writer, AlterTable alterTable) {
+ String tableSpace = platformDdl.extract(alterTable.getTablespace());
+ String indexSpace = platformDdl.extract(alterTable.getIndexTablespace());
+ String lobSpace = platformDdl.extract(alterTable.getLobTablespace());
+ if (hasValue(tableSpace)
+ || hasValue(indexSpace)
+ || hasValue(lobSpace)) {
+
+ writer.apply().appendStatement(platformDdl.alterTableTablespace(alterTable.getName(),
+ DdlHelp.toTablespace(tableSpace),
+ DdlHelp.toTablespace(indexSpace),
+ DdlHelp.toTablespace(lobSpace)));
+ }
+ }
+
/**
* Add drop column DDL.
*/
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 b8ad7ca2d..e88c78a67 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
@@ -15,6 +15,7 @@ import io.ebeaninternal.dbmigration.migration.Column;
* DB2 platform specific DDL.
*/
public class DB2Ddl extends PlatformDdl {
+ private static final String MOVE_TABLE = "CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'%s','%s','%s','%s','','','','','','MOVE')";
public DB2Ddl(DatabasePlatform platform) {
super(platform);
@@ -29,6 +30,16 @@ public class DB2Ddl extends PlatformDdl {
this.historyDdl = new Db2HistoryDdl();
}
+ @Override
+ public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
+ if(tableSpace == null) {
+ // if no tableSpace set, use the default tablespace USERSPACE1
+ return String.format(MOVE_TABLE, tablename.toUpperCase(), "USERSPACE1", "USERSPACE1", "USERSPACE1");
+ } else {
+ return String.format(MOVE_TABLE, tablename.toUpperCase(), tableSpace, indexSpace, lobSpace);
+ }
+ }
+
@Override
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
if (nullableColumns == null || nullableColumns.length == 0) {
@@ -51,6 +62,11 @@ public class DB2Ddl extends PlatformDdl {
return sb.toString();
}
+ @Override
+ public void addTablespace(DdlBuffer apply, String tablespaceName, String indexTablespace, String lobTablespace) {
+ apply.append(" in ").append(tablespaceName).append(" index in ").append(indexTablespace).append(" long in ").append(lobTablespace);
+ }
+
@Override
public void alterTableAddColumn(DdlWrite writer, String tableName, Column column, boolean onHistoryTable, String defaultValue) {
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
index 17855e8fa..fa11e4899 100644
--- 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
@@ -40,9 +40,20 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
// DB2 requires an EXACT copy (same column types with null/non-null, same order)
addSysPeriodColumns(writer, tableName);
- writer.applyPostAlter().append("create table ").append(historyTableName)
- .append(" as (select * from ").append(tableName).append(") with no data").endOfStatement();
+ DdlBuffer tableBuf = writer.applyPostAlter();
+ tableBuf.append("create table ").append(historyTableName)
+ .append(" as (select * from ").append(tableName).append(") with no data");
+ if (table.getTablespaceMeta() != null) {
+ String tableSpace = platformDdl.extract(table.getTablespaceMeta().getTablespaceName());
+ if (tableSpace != null && !tableSpace.isEmpty()) {
+ platformDdl.addTablespace(tableBuf,
+ tableSpace,
+ platformDdl.extract(table.getTablespaceMeta().getIndexTablespace()),
+ platformDdl.extract(table.getTablespaceMeta().getLobTablespace()));
+ }
+ }
+ tableBuf.endOfStatement();
enableSystemVersioning(writer.applyPostAlter(), tableName);
platformDdl.alterTable(writer, tableName).setHistoryHandled();
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java
index f46dd6977..1fbe97c15 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java
@@ -163,6 +163,8 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected void createHistoryTable(DdlBuffer apply, MTable table) {
createHistoryTableAs(apply, table);
createHistoryTableWithPeriod(apply);
+ // TODO: add tablespace here (currently no DbTriggerBased platforms with tablespace support)
+ apply.endOfStatement();
}
protected void createHistoryTableAs(DdlBuffer apply, MTable table) {
@@ -183,7 +185,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
writeColumnDefinition(apply, sysPeriodStart, sysPeriodType);
apply.append(",").newLine();
writeColumnDefinition(apply, sysPeriodEnd, sysPeriodType);
- apply.newLine().append(")").endOfStatement();
+ apply.newLine().append(")");
}
/**
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DdlHelp.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DdlHelp.java
index ceb531530..5a292716e 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DdlHelp.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DdlHelp.java
@@ -1,6 +1,8 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
public class DdlHelp {
+ public static final String TABLESPACE_DEFAULT = "$TABLESPACE_DEFAULT";
+
public static final String DROP_DEFAULT = "DROP DEFAULT";
public static final String DROP_COMMENT = "DROP COMMENT";
@@ -36,4 +38,15 @@ public class DdlHelp {
public static boolean isDropForeignKey(String value) {
return DROP_FOREIGN_KEY.equals(value);
}
+
+ /**
+ * Returns the tablespace. Returns null, if this is the special '$TABLESPACE_DEFAULT' value.
+ */
+ public static String toTablespace(String tablespace) {
+ if (TABLESPACE_DEFAULT.equals(tablespace)) {
+ return null;
+ } else {
+ return tablespace;
+ }
+ }
}
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
index 7807d9252..5ade5a09a 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
@@ -317,10 +317,13 @@ public class PlatformDdl {
// if columnType is different for different platforms, use pattern
// @Column(columnDefinition = PLATFORM1;DEFINITION1;PLATFORM2;DEFINITON2;DEFINITON-DEFAULT)
// e.g. @Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
- private String extract(String type) {
- String[] tmp = type.split(";");
+ protected String extract(String type) {
+ if (type == null) {
+ return null;
+ }
+ String[] tmp = type.split(";", -1); // do not discard trailing empty strings
if (tmp.length % 2 == 0) {
- throw new IllegalArgumentException("You need an odd number of arguments. See Issue #2559 for details");
+ throw new IllegalArgumentException("You need an odd number of arguments in '" + type + "'. See Issue #2559 for details");
}
for (int i = 0; i < tmp.length - 2; i += 2) {
String[] platforms = tmp[i].split(",");
@@ -783,6 +786,23 @@ public class PlatformDdl {
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) {
// only supported by postgres initially
}
+
+ /**
+ * Adds tablespace declaration. Now only supported for db2.
+ */
+ public void addTablespace(DdlBuffer apply, String tablespaceName, String indexTablespace, String lobTablespace) {
+ throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
+ }
+
+ /**
+ * Moves the table to an other tablespace.
+ */
+ public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
+ if (tableSpace != null || indexSpace != null || lobSpace != null) {
+ throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
+ }
+ return null;
+ }
protected String quote(String dbName) {
return platform.convertQuotedIdentifiers(dbName);
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/AlterTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/AlterTable.java
new file mode 100644
index 000000000..9e697196c
--- /dev/null
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/AlterTable.java
@@ -0,0 +1,526 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2022.02.01 at 12:03:38 PM CET
+//
+
+
+package io.ebeaninternal.dbmigration.migration;
+
+import java.math.BigInteger;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <attGroup ref="{http://ebean-orm.github.io/xml/ns/dbmigration}tablespaceAttributes"/>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="newName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="partitionMode" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="partitionColumn" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="identityType" type="{http://ebean-orm.github.io/xml/ns/dbmigration}identityType" />
+ * <attribute name="identityStart" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
+ * <attribute name="identityIncrement" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
+ * <attribute name="identityCache" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
+ * <attribute name="identityGenerated" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="sequenceName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="sequenceInitial" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
+ * <attribute name="sequenceAllocate" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
+ * <attribute name="pkName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="storageEngine" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "")
+@XmlRootElement(name = "alterTable")
+public class AlterTable {
+
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+ @XmlAttribute(name = "newName")
+ protected String newName;
+ @XmlAttribute(name = "partitionMode")
+ protected String partitionMode;
+ @XmlAttribute(name = "partitionColumn")
+ protected String partitionColumn;
+ @XmlAttribute(name = "identityType")
+ protected IdentityType identityType;
+ @XmlAttribute(name = "identityStart")
+ @XmlSchemaType(name = "positiveInteger")
+ protected BigInteger identityStart;
+ @XmlAttribute(name = "identityIncrement")
+ @XmlSchemaType(name = "positiveInteger")
+ protected BigInteger identityIncrement;
+ @XmlAttribute(name = "identityCache")
+ @XmlSchemaType(name = "positiveInteger")
+ protected BigInteger identityCache;
+ @XmlAttribute(name = "identityGenerated")
+ protected String identityGenerated;
+ @XmlAttribute(name = "sequenceName")
+ protected String sequenceName;
+ @XmlAttribute(name = "sequenceInitial")
+ @XmlSchemaType(name = "positiveInteger")
+ protected BigInteger sequenceInitial;
+ @XmlAttribute(name = "sequenceAllocate")
+ @XmlSchemaType(name = "positiveInteger")
+ protected BigInteger sequenceAllocate;
+ @XmlAttribute(name = "pkName")
+ protected String pkName;
+ @XmlAttribute(name = "storageEngine")
+ protected String storageEngine;
+ @XmlAttribute(name = "tablespace")
+ protected String tablespace;
+ @XmlAttribute(name = "indexTablespace")
+ protected String indexTablespace;
+ @XmlAttribute(name = "lobTablespace")
+ protected String lobTablespace;
+ @XmlAttribute(name = "comment")
+ protected String comment;
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the newName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getNewName() {
+ return newName;
+ }
+
+ /**
+ * Sets the value of the newName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setNewName(String value) {
+ this.newName = value;
+ }
+
+ /**
+ * Gets the value of the partitionMode property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getPartitionMode() {
+ return partitionMode;
+ }
+
+ /**
+ * Sets the value of the partitionMode property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setPartitionMode(String value) {
+ this.partitionMode = value;
+ }
+
+ /**
+ * Gets the value of the partitionColumn property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getPartitionColumn() {
+ return partitionColumn;
+ }
+
+ /**
+ * Sets the value of the partitionColumn property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setPartitionColumn(String value) {
+ this.partitionColumn = value;
+ }
+
+ /**
+ * Gets the value of the identityType property.
+ *
+ * @return
+ * possible object is
+ * {@link IdentityType }
+ *
+ */
+ public IdentityType getIdentityType() {
+ return identityType;
+ }
+
+ /**
+ * Sets the value of the identityType property.
+ *
+ * @param value
+ * allowed object is
+ * {@link IdentityType }
+ *
+ */
+ public void setIdentityType(IdentityType value) {
+ this.identityType = value;
+ }
+
+ /**
+ * Gets the value of the identityStart property.
+ *
+ * @return
+ * possible object is
+ * {@link BigInteger }
+ *
+ */
+ public BigInteger getIdentityStart() {
+ return identityStart;
+ }
+
+ /**
+ * Sets the value of the identityStart property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigInteger }
+ *
+ */
+ public void setIdentityStart(BigInteger value) {
+ this.identityStart = value;
+ }
+
+ /**
+ * Gets the value of the identityIncrement property.
+ *
+ * @return
+ * possible object is
+ * {@link BigInteger }
+ *
+ */
+ public BigInteger getIdentityIncrement() {
+ return identityIncrement;
+ }
+
+ /**
+ * Sets the value of the identityIncrement property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigInteger }
+ *
+ */
+ public void setIdentityIncrement(BigInteger value) {
+ this.identityIncrement = value;
+ }
+
+ /**
+ * Gets the value of the identityCache property.
+ *
+ * @return
+ * possible object is
+ * {@link BigInteger }
+ *
+ */
+ public BigInteger getIdentityCache() {
+ return identityCache;
+ }
+
+ /**
+ * Sets the value of the identityCache property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigInteger }
+ *
+ */
+ public void setIdentityCache(BigInteger value) {
+ this.identityCache = value;
+ }
+
+ /**
+ * Gets the value of the identityGenerated property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getIdentityGenerated() {
+ return identityGenerated;
+ }
+
+ /**
+ * Sets the value of the identityGenerated property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setIdentityGenerated(String value) {
+ this.identityGenerated = value;
+ }
+
+ /**
+ * Gets the value of the sequenceName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getSequenceName() {
+ return sequenceName;
+ }
+
+ /**
+ * Sets the value of the sequenceName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setSequenceName(String value) {
+ this.sequenceName = value;
+ }
+
+ /**
+ * Gets the value of the sequenceInitial property.
+ *
+ * @return
+ * possible object is
+ * {@link BigInteger }
+ *
+ */
+ public BigInteger getSequenceInitial() {
+ return sequenceInitial;
+ }
+
+ /**
+ * Sets the value of the sequenceInitial property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigInteger }
+ *
+ */
+ public void setSequenceInitial(BigInteger value) {
+ this.sequenceInitial = value;
+ }
+
+ /**
+ * Gets the value of the sequenceAllocate property.
+ *
+ * @return
+ * possible object is
+ * {@link BigInteger }
+ *
+ */
+ public BigInteger getSequenceAllocate() {
+ return sequenceAllocate;
+ }
+
+ /**
+ * Sets the value of the sequenceAllocate property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigInteger }
+ *
+ */
+ public void setSequenceAllocate(BigInteger value) {
+ this.sequenceAllocate = value;
+ }
+
+ /**
+ * Gets the value of the pkName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getPkName() {
+ return pkName;
+ }
+
+ /**
+ * Sets the value of the pkName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setPkName(String value) {
+ this.pkName = value;
+ }
+
+ /**
+ * Gets the value of the storageEngine property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getStorageEngine() {
+ return storageEngine;
+ }
+
+ /**
+ * Sets the value of the storageEngine property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setStorageEngine(String value) {
+ this.storageEngine = value;
+ }
+
+ /**
+ * Gets the value of the tablespace property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getTablespace() {
+ return tablespace;
+ }
+
+ /**
+ * Sets the value of the tablespace property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setTablespace(String value) {
+ this.tablespace = value;
+ }
+
+ /**
+ * Gets the value of the indexTablespace property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getIndexTablespace() {
+ return indexTablespace;
+ }
+
+ /**
+ * Sets the value of the indexTablespace property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setIndexTablespace(String value) {
+ this.indexTablespace = value;
+ }
+
+ /**
+ * Gets the value of the lobTablespace property.
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ public String getLobTablespace() {
+ return lobTablespace;
+ }
+
+ /**
+ * Sets the value of the lobTablespace property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setLobTablespace(String value) {
+ this.lobTablespace = value;
+ }
+
+ /**
+ * Gets the value of the comment property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * Sets the value of the comment property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setComment(String value) {
+ this.comment = value;
+ }
+
+}
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
index 5fa984ce1..68d971f37 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
@@ -47,6 +47,7 @@ public class ChangeSet {
@XmlElement(name = "configuration", type = Configuration.class),
@XmlElement(name = "sql", type = Sql.class),
@XmlElement(name = "createTable", type = CreateTable.class),
+ @XmlElement(name = "alterTable", type = AlterTable.class),
@XmlElement(name = "dropTable", type = DropTable.class),
@XmlElement(name = "renameTable", type = RenameTable.class),
@XmlElement(name = "addTableComment", type = AddTableComment.class),
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
index 8c451d2ec..da87ee195 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
@@ -99,6 +99,8 @@ public class CreateTable {
protected String tablespace;
@XmlAttribute(name = "indexTablespace")
protected String indexTablespace;
+ @XmlAttribute(name = "lobTablespace")
+ protected String lobTablespace;
@XmlAttribute(name = "comment")
protected String comment;
@@ -522,6 +524,26 @@ public class CreateTable {
public void setIndexTablespace(String value) {
this.indexTablespace = value;
}
+
+ /**
+ * Gets the value of the lobTablespace property.
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ public String getLobTablespace() {
+ return lobTablespace;
+ }
+
+ /**
+ * Sets the value of the lobTablespace property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setLobTablespace(String value) {
+ this.lobTablespace = value;
+ }
/**
* Gets the value of the comment property.
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java
index ac15ca0d5..38e530287 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java
@@ -187,6 +187,13 @@ public class ObjectFactory {
return new ChangeSet();
}
+ /**
+ * Create an instance of {@link AlterTable }
+ */
+ public AlterTable createAlterTable() {
+ return new AlterTable();
+ }
+
/**
* Create an instance of {@link AddHistoryTable }
*/
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
index 5a6770732..96cd1b494 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
@@ -5,6 +5,7 @@ import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
+import io.ebeaninternal.dbmigration.migration.AlterTable;
import io.ebeaninternal.dbmigration.migration.Column;
import io.ebeaninternal.dbmigration.migration.CreateTable;
import io.ebeaninternal.dbmigration.migration.DropColumn;
@@ -17,6 +18,8 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.IdentityMode;
import io.ebeaninternal.server.deploy.PartitionMeta;
+import io.ebeaninternal.server.deploy.TablespaceMeta;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,6 +29,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import static io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns.split;
@@ -56,11 +60,10 @@ public class MTable {
*/
private boolean draft;
private PartitionMeta partitionMeta;
+ private TablespaceMeta tablespaceMeta;
private String pkName;
private String comment;
- private String tablespace;
private String storageEngine;
- private String indexTablespace;
private IdentityMode identityMode;
private boolean withHistory;
private final Map columns = new LinkedHashMap<>();
@@ -93,6 +96,7 @@ public class MTable {
this.identityMode = descriptor.identityMode();
this.storageEngine = descriptor.storageEngine();
this.partitionMeta = descriptor.partitionMeta();
+ this.tablespaceMeta = descriptor.tablespaceMeta();
this.comment = descriptor.dbComment();
if (descriptor.isHistorySupport()) {
withHistory = true;
@@ -104,11 +108,28 @@ public class MTable {
}
/**
- * Construct for element collection or intersection table.
+ * Constructor for test cases only!
*/
+ @Deprecated
public MTable(String name) {
+ this(name, null, null);
+ }
+
+ /**
+ * Construct for element collection or intersection table. They have same table space and storage engine.
+ */
+ public MTable(String name, BeanDescriptor> descriptor) {
+ this(name, descriptor.tablespaceMeta(), descriptor.storageEngine());
+ }
+
+ /**
+ * Constructor for dependant tables (draft/element collection or intersection).
+ */
+ private MTable(String name, TablespaceMeta tablespaceMeta, String storageEngine) {
this.name = name;
this.identityMode = IdentityMode.NONE;
+ this.tablespaceMeta = tablespaceMeta;
+ this.storageEngine = storageEngine;
}
/**
@@ -118,7 +139,7 @@ public class MTable {
* later when creating the CreateTable object.
*/
public MTable createDraftTable() {
- draftTable = new MTable(name + "_draft");
+ draftTable = new MTable(name + "_draft", this.tablespaceMeta, this.storageEngine);
draftTable.draft = true;
draftTable.whenCreatedColumn = whenCreatedColumn;
// compoundKeys
@@ -138,8 +159,13 @@ public class MTable {
this.pkName = createTable.getPkName();
this.comment = createTable.getComment();
this.storageEngine = createTable.getStorageEngine();
- this.tablespace = createTable.getTablespace();
- this.indexTablespace = createTable.getIndexTablespace();
+ if (createTable.getTablespace() != null) {
+ this.tablespaceMeta = new TablespaceMeta(createTable.getTablespace(),
+ createTable.getIndexTablespace() != null ? createTable.getIndexTablespace() : createTable.getTablespace(),
+ createTable.getLobTablespace() != null ? createTable.getLobTablespace() : createTable.getTablespace());
+ } else {
+ this.tablespaceMeta = null;
+ }
this.withHistory = Boolean.TRUE.equals(createTable.isWithHistory());
this.draft = Boolean.TRUE.equals(createTable.isDraft());
this.identityMode = fromCreateTable(createTable);
@@ -210,8 +236,11 @@ public class MTable {
createTable.setPartitionColumn(partitionMeta.getProperty());
}
createTable.setStorageEngine(storageEngine);
- createTable.setTablespace(tablespace);
- createTable.setIndexTablespace(indexTablespace);
+ if (tablespaceMeta != null) {
+ createTable.setTablespace(tablespaceMeta.getTablespaceName());
+ createTable.setIndexTablespace(tablespaceMeta.getIndexTablespace());
+ createTable.setLobTablespace(tablespaceMeta.getLobTablespace());
+ }
toCreateTable(identityMode, createTable);
if (withHistory) {
createTable.setWithHistory(Boolean.TRUE);
@@ -266,6 +295,8 @@ public class MTable {
compareCompoundKeys(modelDiff, newTable);
compareUniqueKeys(modelDiff, newTable);
+ compareTableAttrs(modelDiff, newTable);
+
}
private void compareColumns(ModelDiff modelDiff, MTable newTable) {
@@ -335,6 +366,29 @@ public class MTable {
modelDiff.addUniqueConstraint(newKey.addUniqueConstraint(name));
}
}
+
+ private void compareTableAttrs(ModelDiff modelDiff, MTable newTable) {
+ AlterTable alterTable = new AlterTable();
+ alterTable.setName(newTable.getName());
+ boolean altered = false;
+
+ if (!Objects.equals(tablespaceMeta, newTable.getTablespaceMeta())) {
+ if (newTable.getTablespaceMeta() == null) {
+ alterTable.setTablespace(DdlHelp.TABLESPACE_DEFAULT);
+ alterTable.setIndexTablespace(DdlHelp.TABLESPACE_DEFAULT);
+ alterTable.setLobTablespace(DdlHelp.TABLESPACE_DEFAULT);
+ } else {
+ alterTable.setTablespace(newTable.getTablespaceMeta().getTablespaceName());
+ alterTable.setIndexTablespace(newTable.getTablespaceMeta().getIndexTablespace());
+ alterTable.setLobTablespace(newTable.getTablespaceMeta().getLobTablespace());
+ }
+ altered = true;
+ }
+
+ if (altered) {
+ modelDiff.addAlterTable(alterTable);
+ }
+ }
/**
* Apply AddColumn migration.
@@ -424,13 +478,13 @@ public class MTable {
public void setComment(String comment) {
this.comment = comment;
}
-
- public String getTablespace() {
- return tablespace;
+
+ public void setTablespaceMeta(TablespaceMeta tablespaceMeta) {
+ this.tablespaceMeta = tablespaceMeta;
}
-
- public String getIndexTablespace() {
- return indexTablespace;
+
+ public TablespaceMeta getTablespaceMeta() {
+ return tablespaceMeta;
}
public boolean isWithHistory() {
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java
index 0da3600c7..c9ef40e2d 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java
@@ -8,6 +8,7 @@ import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
+import io.ebeaninternal.dbmigration.migration.AlterTable;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.ChangeSetType;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
@@ -19,6 +20,7 @@ import io.ebeaninternal.dbmigration.migration.DropTable;
import io.ebeaninternal.dbmigration.migration.Migration;
import io.ebeaninternal.dbmigration.migration.RenameColumn;
import io.ebeaninternal.dbmigration.migration.Sql;
+import io.ebeaninternal.server.deploy.TablespaceMeta;
import java.util.ArrayList;
import java.util.Collection;
@@ -155,6 +157,8 @@ public class ModelContainer {
applyChange((CreateTable) change);
} else if (change instanceof DropTable) {
applyChange((DropTable) change);
+ } else if (change instanceof AlterTable) {
+ applyChange((AlterTable) change);
} else if (change instanceof AlterColumn) {
applyChange((AlterColumn) change);
} else if (change instanceof AddColumn) {
@@ -261,6 +265,34 @@ public class ModelContainer {
protected void applyChange(DropTable dropTable) {
tables.remove(dropTable.getName());
}
+
+ /**
+ * Apply a AlterTable change to the model.
+ */
+ protected void applyChange(AlterTable alterTable) {
+ MTable table = getTable(alterTable.getName());
+ if (table == null) {
+ throw new IllegalStateException("Table [" + alterTable.getName() + "] does not exist in model?");
+ }
+ // Handle Tablespace change
+ TablespaceMeta ts = table.getTablespaceMeta();
+
+ if (alterTable.getTablespace() != null) {
+ String currentTableSpace = DdlHelp.toTablespace(alterTable.getTablespace());
+ String currentIndexSpace = DdlHelp.toTablespace(alterTable.getIndexTablespace());
+ String currentLobSpace = DdlHelp.toTablespace(alterTable.getLobTablespace());
+
+ if (currentTableSpace != null) {
+ assert currentIndexSpace != null;
+ assert currentLobSpace != null;
+ table.setTablespaceMeta(new TablespaceMeta(currentTableSpace, currentIndexSpace, currentLobSpace));
+ } else {
+ assert currentIndexSpace == null;
+ assert currentLobSpace == null;
+ table.setTablespaceMeta(null);
+ }
+ }
+ }
/**
* Apply a CreateTable change to the model.
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java
index 367c13ca5..9bf5cf0d0 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java
@@ -6,6 +6,7 @@ import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
+import io.ebeaninternal.dbmigration.migration.AlterTable;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.ChangeSetType;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
@@ -252,4 +253,11 @@ public class ModelDiff {
public void addAlterForeignKey(AlterForeignKey alterForeignKey) {
applyChanges.add(alterForeignKey);
}
+
+ /**
+ * Adds a table alter.
+ */
+ public void addAlterTable(AlterTable alterTable) {
+ applyChanges.add(alterTable);
+ }
}
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildElementTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildElementTable.java
index a8a4d944e..210ac57bc 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildElementTable.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildElementTable.java
@@ -18,7 +18,7 @@ public class ModelBuildElementTable {
BeanTable beanTable = manyProp.beanTable();
BeanDescriptor> targetDescriptor = manyProp.targetDescriptor();
- MTable table = new MTable(beanTable.getBaseTable());
+ MTable table = new MTable(beanTable.getBaseTable(), manyProp.descriptor());
VisitProperties.visit(targetDescriptor, new ModelBuildPropertyVisitor(ctx, table, targetDescriptor));
ctx.addTableElementCollection(table);
diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java
index 179de2ef8..763016278 100644
--- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java
+++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java
@@ -62,7 +62,7 @@ class ModelBuildIntersectionTable {
BeanDescriptor> targetDesc = manyProp.targetDescriptor();
String tableName = intersectionTableJoin.getTable();
- MTable table = new MTable(tableName);
+ MTable table = new MTable(tableName, localDesc);
if (!manyProp.isExcludedFromHistory()) {
if (localDesc.isHistorySupport()) {
table.setWithHistory(true);
diff --git a/ebean-ddl-generator/src/main/resources/ebean-dbmigration-1.0.xsd b/ebean-ddl-generator/src/main/resources/ebean-dbmigration-1.0.xsd
index 27fc52cfa..e7ef14be7 100644
--- a/ebean-ddl-generator/src/main/resources/ebean-dbmigration-1.0.xsd
+++ b/ebean-ddl-generator/src/main/resources/ebean-dbmigration-1.0.xsd
@@ -218,6 +218,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -341,6 +362,7 @@
+
@@ -351,6 +373,7 @@
+
diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/BaseDdlHandlerTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/BaseDdlHandlerTest.java
index 092bc75fa..afd56d72c 100644
--- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/BaseDdlHandlerTest.java
+++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/BaseDdlHandlerTest.java
@@ -4,6 +4,7 @@ import io.localtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
+import io.ebean.config.dbplatform.db2.DB2LuwPlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
@@ -42,6 +43,9 @@ public class BaseDdlHandlerTest extends BaseTestCase {
return handler(new HanaPlatform());
}
+ private DdlHandler db2Handler() {
+ return handler(new DB2LuwPlatform());
+ }
@Test
public void addColumn_nullable_noConstraint() throws Exception {
@@ -219,6 +223,19 @@ public class BaseDdlHandlerTest extends BaseTestCase {
assertThat(writer.dropAll().getBuffer().trim()).isEqualTo("drop table foo cascade;");
}
+ @Test
+ public void createTableWithTableSpace() throws Exception {
+
+ DdlWrite writer = new DdlWrite();
+ DdlHandler handler = db2Handler();
+
+ handler.generate(writer, Helper.getCreateTable());
+
+ assertThat(writer.toString())
+ .contains("create table foo (")
+ .contains(") in fooSpace index in fooIndexSpace long in fooLobSpace;");
+ }
+
@Test
public void generateChangeSet() throws Exception {
diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_CreateIndexTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_CreateIndexTest.java
index e7b8fab30..73156d0a7 100644
--- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_CreateIndexTest.java
+++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl_CreateIndexTest.java
@@ -2,6 +2,7 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.DB;
import io.ebean.config.DatabaseConfig;
+import io.ebean.config.dbplatform.db2.DB2LuwPlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
@@ -23,6 +24,7 @@ public class PlatformDdl_CreateIndexTest {
private final PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
private final PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServer17Platform());
private final PlatformDdl hanaDdl = PlatformDdlBuilder.create(new HanaPlatform());
+ private final PlatformDdl db2LuwDdl = PlatformDdlBuilder.create(new DB2LuwPlatform());
{
DatabaseConfig config = DB.getDefault().pluginApi().config();
@@ -32,6 +34,7 @@ public class PlatformDdl_CreateIndexTest {
oraDdl.configure(config);
sqlServerDdl.configure(config);
hanaDdl.configure(config);
+ db2LuwDdl.configure(config);
}
WriteCreateIndex writeCreateIndex() {
@@ -71,6 +74,8 @@ public class PlatformDdl_CreateIndexTest {
assertEquals("create unique index ix_mytab_acol on mytab (acol)", sql);
sql = hanaDdl.createIndex(createIndex);
assertThat(sql).isEqualTo("-- explicit index \"ix_mytab_acol\" for single column \"acol\" of table \"mytab\" is not necessary");
+ sql = db2LuwDdl.createIndex(createIndex);
+ assertThat(sql).isEqualTo("create unique index ix_mytab_acol on mytab (acol)");
}
@Test
@@ -95,4 +100,21 @@ public class PlatformDdl_CreateIndexTest {
assertEquals("create index ix_mytab_acol on mytab (acol)", sql);
}
+ @Test
+ public void db2luw_fkeyCreateIndex() {
+ String sql = db2LuwDdl.createIndex(fkeyCreateIndex(true));
+ assertEquals("create unique index ix_mytab_acol on mytab (acol)", sql);
+
+ sql = db2LuwDdl.createIndex(fkeyCreateIndex(false));
+ assertEquals("create index ix_mytab_acol on mytab (acol)", sql);
+ }
+
+ @Test
+ public void db2luw_tablespaceIndex() {
+ String sql = db2LuwDdl.createIndex(new WriteCreateIndex("ix_mytab_acol", "mytab", new String[]{"acol"}, false));
+ assertEquals("create index ix_mytab_acol on mytab (acol)", sql);
+ sql = db2LuwDdl.createIndex(new WriteCreateIndex("ix_mytab_acol", "mytab", new String[]{"acol"}, true));
+ assertEquals("create unique index ix_mytab_acol on mytab (acol)", sql);
+ }
+
}
diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java
index da493f9ef..18fdefb3e 100644
--- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java
+++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java
@@ -34,8 +34,9 @@ public class ModelContainerApplyTest {
MTable foo = model.getTable("foo");
assertThat(foo.getComment()).isEqualTo("comment");
- assertThat(foo.getTablespace()).isEqualTo("fooSpace");
- assertThat(foo.getIndexTablespace()).isEqualTo("fooIndexSpace");
+ assertThat(foo.getTablespaceMeta().getTablespaceName()).isEqualTo("db2;fooSpace;");
+ assertThat(foo.getTablespaceMeta().getIndexTablespace()).isEqualTo("db2;fooIndexSpace;");
+ assertThat(foo.getTablespaceMeta().getLobTablespace()).isEqualTo("db2;fooLobSpace;");
assertThat(foo.isWithHistory()).isEqualTo(false);
assertThat(foo.allColumns()).extracting("name").contains("col1", "col3", "added_to_foo");
}
diff --git a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java
index 06390a20e..22b03d983 100644
--- a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java
+++ b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java
@@ -47,6 +47,10 @@ public abstract class BaseTestCase {
public boolean isSqlServer() {
return Platform.SQLSERVER == platform();
}
+
+ public boolean isDB2() {
+ return Platform.DB2 == platform();
+ }
public boolean isH2() {
return Platform.H2 == platform();
diff --git a/ebean-ddl-generator/src/test/resources/container/test-create-table.xml b/ebean-ddl-generator/src/test/resources/container/test-create-table.xml
index 9c5bc2e30..303aa9c01 100644
--- a/ebean-ddl-generator/src/test/resources/container/test-create-table.xml
+++ b/ebean-ddl-generator/src/test/resources/container/test-create-table.xml
@@ -4,7 +4,7 @@
-
+
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 a7461173e..9174772fe 100644
--- a/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java
+++ b/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java
@@ -95,6 +95,10 @@ public class DbMigrationTest extends BaseTestCase {
if (isSqlServer() || isMariaDB() || isMySql() || isHana()) {
runScript("I__create_procs.sql");
}
+
+ if(isDb2()) {
+ runScript("I__create_tablespaces.sql");
+ }
runScript("1.0__initial.sql");
diff --git a/ebean-test/src/test/java/misc/migration/v1_0/EBasic.java b/ebean-test/src/test/java/misc/migration/v1_0/EBasic.java
index c6a451a9f..e8d8f0763 100644
--- a/ebean-test/src/test/java/misc/migration/v1_0/EBasic.java
+++ b/ebean-test/src/test/java/misc/migration/v1_0/EBasic.java
@@ -5,6 +5,7 @@ import io.ebean.annotation.DbJson;
import io.ebean.annotation.EnumValue;
import io.ebean.annotation.Index;
import io.ebean.annotation.NotNull;
+import io.ebean.annotation.Tablespace;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -20,6 +21,10 @@ import java.util.List;
@Entity
@Table(name = "migtest_e_basic")
+// Note: tablespaces are currently only supported for DB2
+// to be prepared for future (when we support sql server filegroups),
+// we allow to specify the DB-platform here
+@Tablespace(value = "db2;TSTABLES;", index = "db2;INDEXTS;")
public class EBasic {
public enum Status {
diff --git a/ebean-test/src/test/java/misc/migration/v1_0/EHistory.java b/ebean-test/src/test/java/misc/migration/v1_0/EHistory.java
index fe0bcdfe9..ec2381650 100644
--- a/ebean-test/src/test/java/misc/migration/v1_0/EHistory.java
+++ b/ebean-test/src/test/java/misc/migration/v1_0/EHistory.java
@@ -5,8 +5,11 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
+import io.ebean.annotation.Tablespace;
+
@Entity
@Table(name = "migtest_e_history")
+@Tablespace("db2;MAIN;")
public class EHistory {
@Id
diff --git a/ebean-test/src/test/java/misc/migration/v1_1/EBasic.java b/ebean-test/src/test/java/misc/migration/v1_1/EBasic.java
index 6837fc3f9..3ed011c12 100644
--- a/ebean-test/src/test/java/misc/migration/v1_1/EBasic.java
+++ b/ebean-test/src/test/java/misc/migration/v1_1/EBasic.java
@@ -56,7 +56,7 @@ public class EBasic {
"update ${table} set status = 'N' where id = 1" }, platforms = Platform.DB2)
@DbMigration(preAlter = "-- rename all collisions")
@Column(unique = true)
- @Size(max=127)
+ @Size(max = 127)
String description;
@DbJson
diff --git a/ebean-test/src/test/java/misc/migration/v1_1/EHistory.java b/ebean-test/src/test/java/misc/migration/v1_1/EHistory.java
index f67b4c9f2..a8773205d 100644
--- a/ebean-test/src/test/java/misc/migration/v1_1/EHistory.java
+++ b/ebean-test/src/test/java/misc/migration/v1_1/EHistory.java
@@ -5,6 +5,7 @@ import io.ebean.annotation.DbComment;
import io.ebean.annotation.DbMigration;
import io.ebean.annotation.History;
import io.ebean.annotation.Platform;
+import io.ebean.annotation.Tablespace;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -14,6 +15,8 @@ import javax.persistence.Table;
@Table(name = "migtest_e_history")
@History
@DbComment("We have history now")
+// TODO: Should we allow own table space for history?
+@Tablespace("db2;MAIN;")
public class EHistory {
@Id
diff --git a/ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java b/ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java
index bdcd43845..3ba02c2a5 100644
--- a/ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java
+++ b/ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java
@@ -4,10 +4,14 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
+
+import io.ebean.annotation.Tablespace;
+
import java.util.List;
@Entity
@Table(name = "migtest_mtm_c")
+@Tablespace("db2;TESTTS;")
public class MtmChild {
@Id
diff --git a/ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java b/ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java
index de0f3ffc9..3c132c2c9 100644
--- a/ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java
+++ b/ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java
@@ -5,10 +5,14 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
+
+import io.ebean.annotation.Tablespace;
+
import java.util.List;
@Entity
@Table(name = "migtest_mtm_m")
+@Tablespace("db2;TSMASTER;")
public class MtmMaster {
@Id
diff --git a/ebean-test/src/test/java/misc/migration/v1_2/EHistory.java b/ebean-test/src/test/java/misc/migration/v1_2/EHistory.java
index 0e166625c..ab2fbdf33 100644
--- a/ebean-test/src/test/java/misc/migration/v1_2/EHistory.java
+++ b/ebean-test/src/test/java/misc/migration/v1_2/EHistory.java
@@ -5,8 +5,11 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
+import io.ebean.annotation.Tablespace;
+
@Entity
@Table(name = "migtest_e_history")
+@Tablespace("db2;MAIN;")
public class EHistory {
@Id
diff --git a/ebean-test/src/test/resources/extra-ddl.xml b/ebean-test/src/test/resources/extra-ddl.xml
index ba824c38a..130de7fac 100644
--- a/ebean-test/src/test/resources/extra-ddl.xml
+++ b/ebean-test/src/test/resources/extra-ddl.xml
@@ -64,4 +64,41 @@
create index ix_ebasic_jmjb_gin2 on ebasic_json_map_json_b using gin(content jsonb_path_ops);
+
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TSTABLES')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TSTABLES"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'INDEXTS'))
+THEN EXECUTE IMMEDIATE 'CREATE TABLESPACE "INDEXTS"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TESTTS')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TESTTS"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TSMASTER')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TSMASTER"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'MAIN')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "MAIN"';
+END IF;
+END
+$$
+
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 a64383897..20ebe89e7 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
@@ -77,7 +77,7 @@ create table migtest_e_basic (
constraint ck_migtest_e_basic_status check ( status in ('N','A','I')),
constraint ck_migtest_e_basic_status2 check ( status2 in ('N','A','I')),
constraint pk_migtest_e_basic primary key (id)
-);
+) in TSTABLES index in INDEXTS long in TSTABLES;
create table migtest_e_enum (
id integer generated by default as identity not null,
@@ -90,7 +90,7 @@ create table migtest_e_history (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_history primary key (id)
-);
+) in MAIN index in MAIN long in MAIN;
create table migtest_e_history2 (
id integer generated by default as identity not null,
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 1cc7b4b1d..9ed658aca 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
@@ -87,18 +87,18 @@ create table migtest_mtm_c_migtest_mtm_m (
migtest_mtm_c_id integer not null,
migtest_mtm_m_id bigint not null,
constraint pk_migtest_mtm_c_migtest_mtm_m primary key (migtest_mtm_c_id,migtest_mtm_m_id)
-);
+) in TESTTS index in TESTTS long in TESTTS;
create table migtest_mtm_m_migtest_mtm_c (
migtest_mtm_m_id bigint not null,
migtest_mtm_c_id integer not null,
constraint pk_migtest_mtm_m_migtest_mtm_c primary key (migtest_mtm_m_id,migtest_mtm_c_id)
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
create table migtest_mtm_m_phone_numbers (
migtest_mtm_m_id bigint not null,
value varchar(255) not null
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
update migtest_e_basic set status = 'A' where status is null;
@@ -107,6 +107,7 @@ update migtest_e_basic set status = 'A' where status is null;
update migtest_e_basic set status = 'N' where id = 1;
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_E_BASIC','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -119,6 +120,8 @@ alter table migtest_e_history5 drop versioning;
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
alter table migtest_e_history6 drop versioning;
alter table "table" drop versioning;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','TESTTS','TESTTS','TESTTS','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','TSMASTER','TSMASTER','TSMASTER','','','','','','MOVE');
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
@@ -182,7 +185,7 @@ 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 as (select * from migtest_e_history) with no data;
+create table migtest_e_history_history as (select * from migtest_e_history) with no data in MAIN index in MAIN long in MAIN;
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';
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 2fcd77858..545ccdeb4 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
@@ -167,6 +167,8 @@ 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;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- apply alter tables
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
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 69a27f3a5..efd9f0faa 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 @@
--1073246286, 1.0__initial.sql
-2043476851, 1.1.sql
+-2035307143, 1.0__initial.sql
+2129080414, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-1155358918, 1.3.sql
+1302478095, 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 578d7cdff..fc3c2054e 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
@@ -77,7 +77,7 @@ create table migtest_e_basic (
constraint ck_mgtst__bsc_stts check ( status in ('N','A','I')),
constraint ck_mgtst__b_z543fg check ( status2 in ('N','A','I')),
constraint pk_migtest_e_basic primary key (id)
-);
+) in TSTABLES index in INDEXTS long in TSTABLES;
create table migtest_e_enum (
id integer generated by default as identity not null,
@@ -90,7 +90,7 @@ create table migtest_e_history (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_history primary key (id)
-);
+) in MAIN index in MAIN long in MAIN;
create table migtest_e_history2 (
id integer generated by default as identity not null,
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 21013eea0..82051c0b1 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
@@ -87,18 +87,18 @@ create table migtest_mtm_c_migtest_mtm_m (
migtest_mtm_c_id integer not null,
migtest_mtm_m_id bigint not null,
constraint pk_migtest_mtm_c_migtest_mtm_m primary key (migtest_mtm_c_id,migtest_mtm_m_id)
-);
+) in TESTTS index in TESTTS long in TESTTS;
create table migtest_mtm_m_migtest_mtm_c (
migtest_mtm_m_id bigint not null,
migtest_mtm_c_id integer not null,
constraint pk_migtest_mtm_m_migtest_mtm_c primary key (migtest_mtm_m_id,migtest_mtm_c_id)
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
create table migtest_mtm_m_phone_numbers (
migtest_mtm_m_id bigint not null,
value varchar(255) not null
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
update migtest_e_basic set status = 'A' where status is null;
@@ -107,6 +107,7 @@ update migtest_e_basic set status = 'A' where status is null;
update migtest_e_basic set status = 'N' where id = 1;
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_E_BASIC','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -119,6 +120,8 @@ alter table migtest_e_history5 drop versioning;
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
alter table migtest_e_history6 drop versioning;
alter table "table" drop versioning;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','TESTTS','TESTTS','TESTTS','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','TSMASTER','TSMASTER','TSMASTER','','','','','','MOVE');
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
@@ -182,7 +185,7 @@ create unique index uq_mgtst__b_ucfcne on migtest_e_basic(status,indextest1) exc
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 as (select * from migtest_e_history) with no data;
+create table migtest_e_history_history as (select * from migtest_e_history) with no data in MAIN index in MAIN long in MAIN;
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';
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 358d219a8..cdd739792 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
@@ -167,6 +167,8 @@ 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;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- apply alter tables
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
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 880eb4bf6..359f08af9 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 @@
-2054922533, 1.0__initial.sql
-1256892738, 1.1.sql
+-867624537, 1.0__initial.sql
+-1885896768, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-1760988648, 1.3.sql
+-29831669, 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 c2235d9c9..8a9d1adeb 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
@@ -77,7 +77,7 @@ create table migtest_e_basic (
constraint ck_migtest_e_basic_status check ( status in ('N','A','I')),
constraint ck_migtest_e_basic_status2 check ( status2 in ('N','A','I')),
constraint pk_migtest_e_basic primary key (id)
-);
+) in TSTABLES index in INDEXTS long in TSTABLES;
create table migtest_e_enum (
id integer generated by default as identity not null,
@@ -90,7 +90,7 @@ create table migtest_e_history (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_history primary key (id)
-);
+) in MAIN index in MAIN long in MAIN;
create table migtest_e_history2 (
id integer generated by default as identity not null,
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 2fb812410..a5d6e0287 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
@@ -87,18 +87,18 @@ create table migtest_mtm_c_migtest_mtm_m (
migtest_mtm_c_id integer not null,
migtest_mtm_m_id bigint not null,
constraint pk_migtest_mtm_c_migtest_mtm_m primary key (migtest_mtm_c_id,migtest_mtm_m_id)
-);
+) in TESTTS index in TESTTS long in TESTTS;
create table migtest_mtm_m_migtest_mtm_c (
migtest_mtm_m_id bigint not null,
migtest_mtm_c_id integer not null,
constraint pk_migtest_mtm_m_migtest_mtm_c primary key (migtest_mtm_m_id,migtest_mtm_c_id)
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
create table migtest_mtm_m_phone_numbers (
migtest_mtm_m_id bigint not null,
value varchar(255) not null
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
update migtest_e_basic set status = 'A' where status is null;
@@ -107,6 +107,7 @@ update migtest_e_basic set status = 'A' where status is null;
update migtest_e_basic set status = 'N' where id = 1;
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_E_BASIC','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -119,6 +120,8 @@ alter table migtest_e_history5 drop versioning;
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
alter table migtest_e_history6 drop versioning;
alter table "table" drop versioning;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','TESTTS','TESTTS','TESTTS','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','TSMASTER','TSMASTER','TSMASTER','','','','','','MOVE');
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
@@ -182,7 +185,7 @@ 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 as (select * from migtest_e_history) with no data;
+create table migtest_e_history_history as (select * from migtest_e_history) with no data in MAIN index in MAIN long in MAIN;
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';
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 9dbb719d6..b5d82e860 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
@@ -167,6 +167,8 @@ 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;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- apply alter tables
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/I__create_tablespaces.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/I__create_tablespaces.sql
new file mode 100644
index 000000000..84692a31d
--- /dev/null
+++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/I__create_tablespaces.sql
@@ -0,0 +1,36 @@
+
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TSTABLES')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TSTABLES"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'INDEXTS'))
+THEN EXECUTE IMMEDIATE 'CREATE TABLESPACE "INDEXTS"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TESTTS')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TESTTS"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TSMASTER')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "TSMASTER"';
+END IF;
+END
+$$
+delimiter $$
+BEGIN
+IF (NOT exists (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'MAIN')) THEN
+EXECUTE IMMEDIATE 'CREATE TABLESPACE "MAIN"';
+END IF;
+END
+$$
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 9d4b61aa7..27ba5f2fc 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,8 @@
--1519091511, 1.0__initial.sql
--370964456, 1.1.sql
+1307787475, I__create_tablespaces.sql
+-1520031543, 1.0__initial.sql
+1233890256, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-591329540, 1.3.sql
+-1775325396, 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 c2235d9c9..8a9d1adeb 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
@@ -77,7 +77,7 @@ create table migtest_e_basic (
constraint ck_migtest_e_basic_status check ( status in ('N','A','I')),
constraint ck_migtest_e_basic_status2 check ( status2 in ('N','A','I')),
constraint pk_migtest_e_basic primary key (id)
-);
+) in TSTABLES index in INDEXTS long in TSTABLES;
create table migtest_e_enum (
id integer generated by default as identity not null,
@@ -90,7 +90,7 @@ create table migtest_e_history (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_history primary key (id)
-);
+) in MAIN index in MAIN long in MAIN;
create table migtest_e_history2 (
id integer generated by default as identity not null,
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 2fb812410..a5d6e0287 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
@@ -87,18 +87,18 @@ create table migtest_mtm_c_migtest_mtm_m (
migtest_mtm_c_id integer not null,
migtest_mtm_m_id bigint not null,
constraint pk_migtest_mtm_c_migtest_mtm_m primary key (migtest_mtm_c_id,migtest_mtm_m_id)
-);
+) in TESTTS index in TESTTS long in TESTTS;
create table migtest_mtm_m_migtest_mtm_c (
migtest_mtm_m_id bigint not null,
migtest_mtm_c_id integer not null,
constraint pk_migtest_mtm_m_migtest_mtm_c primary key (migtest_mtm_m_id,migtest_mtm_c_id)
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
create table migtest_mtm_m_phone_numbers (
migtest_mtm_m_id bigint not null,
value varchar(255) not null
-);
+) in TSMASTER index in TSMASTER long in TSMASTER;
update migtest_e_basic set status = 'A' where status is null;
@@ -107,6 +107,7 @@ update migtest_e_basic set status = 'A' where status is null;
update migtest_e_basic set status = 'N' where id = 1;
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_E_BASIC','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -119,6 +120,8 @@ alter table migtest_e_history5 drop versioning;
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
alter table migtest_e_history6 drop versioning;
alter table "table" drop versioning;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','TESTTS','TESTTS','TESTTS','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','TSMASTER','TSMASTER','TSMASTER','','','','','','MOVE');
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
@@ -182,7 +185,7 @@ 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 as (select * from migtest_e_history) with no data;
+create table migtest_e_history_history as (select * from migtest_e_history) with no data in MAIN index in MAIN long in MAIN;
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';
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 9dbb719d6..b5d82e860 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
@@ -167,6 +167,8 @@ 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;
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_C','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
+CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_MTM_M','USERSPACE1','USERSPACE1','USERSPACE1','','','','','','MOVE');
-- apply alter tables
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
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 9d4b61aa7..cb4a3dfc1 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 @@
--1519091511, 1.0__initial.sql
--370964456, 1.1.sql
+-1520031543, 1.0__initial.sql
+1233890256, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-591329540, 1.3.sql
+-1775325396, 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/model/1.0__initial.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml
index 001f3797f..082c9bd3a 100644
--- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml
+++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml
@@ -37,7 +37,7 @@
-
+
@@ -64,7 +64,7 @@
-
+
diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml
index 410615793..2b7b577e3 100644
--- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml
+++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml
@@ -47,6 +47,7 @@
+
@@ -79,19 +80,21 @@
-
+
+
-
+
+
-
+
diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml
index 1c266ccae..1609ed17f 100644
--- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml
+++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml
@@ -41,6 +41,8 @@
+
+
diff --git a/ebean-test/testconfig/ebean-db2.properties b/ebean-test/testconfig/ebean-db2.properties
index 40e375ef5..4ffab60f1 100644
--- a/ebean-test/testconfig/ebean-db2.properties
+++ b/ebean-test/testconfig/ebean-db2.properties
@@ -1,5 +1,7 @@
ebean.test.platform=db2
ebean.test.dbName=unit
-ebean.test.dbPassword=unit
+# we need admin user to call the procedure SYSPROC.ADMIN_MOVE_TABLE
+ebean.test.username=admin
+ebean.test.password=admin
datasource.default=db2-11
ebean.db2-11.databasePlatformName=db2luw