Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/Db2HistoryDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/HanaHistoryDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
#	ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresHistoryDdl.java
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql
#	ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations
#	ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml
This commit is contained in:
Roland Praml
2022-03-22 11:07:36 +01:00
141 changed files with 1478 additions and 646 deletions
+1
View File
@@ -3,6 +3,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ebean-orm/ebean/blob/master/LICENSE)
[![Multi-JDK Build](https://github.com/ebean-orm/ebean/actions/workflows/multi-jdk-build.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/multi-jdk-build.yml)
[![JDK 18-ea](https://github.com/ebean-orm/ebean/actions/workflows/jdk-18-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/jdk-18-ea.yml)
[![JDK EA](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/jdk-ea.yml)
[![H2Database](https://github.com/ebean-orm/ebean/actions/workflows/h2database.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/h2database.yml)
[![Postgres](https://github.com/ebean-orm/ebean/actions/workflows/postgres.yml/badge.svg)](https://github.com/ebean-orm/ebean/actions/workflows/postgres.yml)
@@ -184,17 +184,4 @@ public class DbConstraintNaming {
return normalise.normaliseColumn(tableName);
}
/**
* Lower case the table name checking for quoted identifiers.
*/
public String lowerTableName(String tableName) {
return normalise.lowerTableName(tableName);
}
/**
* Lower case the column name checking for quoted identifiers.
*/
public String lowerColumnName(String name) {
return normalise.lowerColumnName(name);
}
}
@@ -55,53 +55,19 @@ public class DbConstraintNormalise {
return value.replace("(","").replace(")","");
}
/**
* Lower case the table name checking for quoted identifiers.
*/
public String lowerTableName(String tableName) {
if (lowerCaseTables && notQuoted(tableName)) {
return tableName.toLowerCase();
}
return tableName;
}
/**
* Lower case the column name checking for quoted identifiers.
*/
public String lowerColumnName(String name) {
if (lowerCaseColumns && notQuoted(name)) {
return name.toLowerCase();
}
return name;
}
/**
* Trim off the platform quoted identifier quotes like [ ' and ".
*/
public boolean notQuoted(String tableName) {
public String trimQuotes(String identifier) {
// remove quoted identifier characters
for (String quotedIdentifier : quotedIdentifiers) {
if (tableName.contains(quotedIdentifier)) {
return false;
}
}
return true;
}
/**
* Trim off the platform quoted identifier quotes like [ ' and ".
*/
public String trimQuotes(String tableName) {
if (tableName == null) {
if (identifier == null) {
return "";
}
// remove quoted identifier characters
for (String quotedIdentifier : quotedIdentifiers) {
tableName = tableName.replace(quotedIdentifier, "");
identifier = identifier.replace(quotedIdentifier, "");
}
return tableName;
return identifier;
}
@@ -165,7 +165,7 @@ public class DatabasePlatform {
* want to use quoted identifiers for. The backticks get converted to the
* appropriate characters in convertQuotedIdentifiers
*/
private static final char BACK_TICK = '`';
private static final char[] QUOTED_IDENTIFIERS = new char[] { '"', '\'', '[', ']', '`' };
/**
* The non-escaped like clause (to stop slash being escaped on some platforms).
@@ -662,8 +662,8 @@ public class DatabasePlatform {
public String convertQuotedIdentifiers(String dbName) {
// Ignore null values e.g. schema name or catalog
if (dbName != null && !dbName.isEmpty()) {
if (dbName.charAt(0) == BACK_TICK) {
if (dbName.charAt(dbName.length() - 1) == BACK_TICK) {
if (isQuote(dbName.charAt(0))) {
if (isQuote(dbName.charAt(dbName.length() - 1))) {
return openQuote + dbName.substring(1, dbName.length() - 1) + closeQuote;
} else {
log.error("Missing backquote on [" + dbName + "]");
@@ -675,6 +675,15 @@ public class DatabasePlatform {
return dbName;
}
private boolean isQuote(char ch) {
for (char identifer : QUOTED_IDENTIFIERS) {
if (identifer == ch) {
return true;
}
}
return false;
}
/**
* Remove quoted identifier quotes from the table or column name if present.
*/
@@ -35,7 +35,7 @@ public final class CacheIdLookupMany<T> implements CacheIdLookup<T> {
@Override
public List<T> removeHits(BeanCacheResult<T> cacheResult) {
Set<Object> hitIds = new HashSet<>();
List<T> beans = new ArrayList<>(hitIds.size());
List<T> beans = new ArrayList<>();
for (BeanCacheResult.Entry<T> hit : cacheResult.hits()) {
hitIds.add(hit.getKey());
beans.add(hit.getBean());
@@ -40,7 +40,7 @@ abstract class AbstractTextExpression extends AbstractExpression {
@Override
public void queryBindKey(BindValuesKey key) {
// do nothing, only execute against document store
};
}
@Override
public boolean isSameByBind(SpiExpression other) {
@@ -4,8 +4,6 @@ import io.ebeaninternal.api.BindValuesKey;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import java.io.IOException;
/**
* Bitwise expression.
*/
@@ -25,7 +23,7 @@ final class BitwiseExpression extends AbstractExpression {
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
public void writeDocQuery(DocQueryContext context) {
throw new IllegalStateException("Not supported for document queries");
}
@@ -47,12 +47,12 @@ final class DefaultExampleExpression implements SpiExpression, ExampleExpression
private final EntityBean entity;
/**
* Set to true to use case insensitive expressions.
* Set to true to use case-insensitive expressions.
*/
private boolean caseInsensitive;
/**
* The type of like (RAW, STARTS_WITH, ENDS_WITH etc)
* The type of like (RAW, STARTS_WITH, ENDS_WITH)
*/
private LikeType likeType;
@@ -62,7 +62,7 @@ final class DefaultExampleExpression implements SpiExpression, ExampleExpression
private boolean includeZeros;
/**
* The non null bean properties and found and together added as a list of
* The non-null bean properties and found and together added as a list of
* expressions (like or equal to expressions).
*/
private ArrayList<SpiExpression> list;
@@ -71,8 +71,8 @@ final class DefaultExampleExpression implements SpiExpression, ExampleExpression
/**
* Construct the query by example expression.
*
* @param entity the example entity with non null property values
* @param caseInsensitive if true use case insensitive expressions
* @param entity the example entity with non-null property values
* @param caseInsensitive if true use case-insensitive expressions
* @param likeType the type of Like wild card used
*/
DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType) {
@@ -303,9 +303,7 @@ final class DefaultExampleExpression implements SpiExpression, ExampleExpression
*/
private boolean isZero(Object value) {
if (value instanceof Number) {
if (((Number) value).doubleValue() == 0) {
return true;
}
return ((Number) value).doubleValue() == 0;
}
return false;
}
@@ -186,7 +186,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
/**
* Case Insensitive Equal To - property equal to the given value (typically
* using a lower() function to make it case insensitive).
* using a lower() function to make it case-insensitive).
*/
@Override
public Expression ieq(String propertyName, String value) {
@@ -198,7 +198,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
/**
* Case Insensitive Equal To - property equal to the given value (typically
* using a lower() function to make it case insensitive).
* using a lower() function to make it case-insensitive).
*/
@Override
public Expression ine(String propertyName, String value) {
@@ -336,7 +336,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Case insensitive {@link #exampleLike(Object)}
* Case-insensitive {@link #exampleLike(Object)}
*/
@Override
public ExampleExpression iexampleLike(Object example) {
@@ -344,7 +344,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Create the query by Example expression which is case sensitive and using
* Create the query by Example expression which is case-sensitive and using
* LikeType.RAW (you need to add you own wildcards % and _).
*/
@Override
@@ -375,9 +375,9 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Case insensitive Like - property like value where the value contains the
* SQL wild card characters % (percentage) and _ (underscore). Typically uses
* a lower() function to make the expression case insensitive.
* Case-insensitive Like - property like value where the value contains the
* SQL wild card characters % (percentage) and _ (underscore). Typically, uses
* a lower() function to make the expression case-insensitive.
*/
@Override
public Expression ilike(String propertyName, String value) {
@@ -397,8 +397,8 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Case insensitive Starts With - property like value%. Typically uses a
* lower() function to make the expression case insensitive.
* Case-insensitive Starts With - property like value%. Typically, uses a
* lower() function to make the expression case-insensitive.
*/
@Override
public Expression istartsWith(String propertyName, String value) {
@@ -414,8 +414,8 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Case insensitive Ends With - property like %value. Typically uses a lower()
* function to make the expression case insensitive.
* Case-insensitive Ends With - property like %value. Typically, uses a lower()
* function to make the expression case-insensitive.
*/
@Override
public Expression iendsWith(String propertyName, String value) {
@@ -431,8 +431,8 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
}
/**
* Case insensitive Contains - property like %value%. Typically uses a lower()
* function to make the expression case insensitive.
* Case-insensitive Contains - property like %value%. Typically, uses a lower()
* function to make the expression case-insensitive.
*/
@Override
public Expression icontains(String propertyName, String value) {
@@ -162,7 +162,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
writeDocQuery(context, null);
} else {
// this is a Top level "text" expressions so we may need to wrap in Bool SHOULD etc.
// this is a Top level "text" expressions, so we may need to wrap in Bool SHOULD etc.
if (list.isEmpty()) {
throw new IllegalStateException("empty expression list?");
}
@@ -71,7 +71,7 @@ public interface DocQueryContext {
void writeIn(String propertyName, Object[] values, boolean not) throws IOException;
/**
* Write an Id in expression.
* Write an ID in expression.
*/
void writeIds(Collection<?> idCollection) throws IOException;
@@ -131,7 +131,7 @@ public interface DocQueryContext {
void writeTextQueryString(String search, TextQueryString options) throws IOException;
/**
* Start a Bool which may contain some of Must, Must Not, Should.
* Start a Bool which may contain Must, Must Not, Should.
*/
void startBoolGroup() throws IOException;
@@ -1,19 +1,11 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.BindValuesKey;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.NaturalKeyQueryData;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.api.SpiExpressionValidation;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.*;
import io.ebeaninternal.api.SpiQuery.Type;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.query.CQuery;
import java.io.IOException;
import java.util.List;
final class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpression {
@@ -52,7 +44,7 @@ final class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreE
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
public void writeDocQuery(DocQueryContext context) {
throw new IllegalStateException("Not supported");
}
@@ -77,7 +69,7 @@ final class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreE
/**
* Compile/build the sub query.
*/
protected CQuery<?> compileSubQuery(BeanQueryRequest<?> queryRequest) {
CQuery<?> compileSubQuery(BeanQueryRequest<?> queryRequest) {
SpiEbeanServer ebeanServer = (SpiEbeanServer) queryRequest.database();
return ebeanServer.compileQuery(Type.SQ_EXISTS, subQuery, queryRequest.transaction());
}
@@ -51,7 +51,7 @@ final class IdExpression extends NonPrepareExpression implements SpiExpression {
@Override
public void addBindValues(SpiExpressionRequest request) {
// 'flatten' EmbeddedId and multiple Id cases
// 'flatten' EmbeddedId and multiple ID cases
// into an array of the underlying scalar field values
DefaultExpressionRequest r = (DefaultExpressionRequest) request;
Object[] bindIdValues = r.getBeanDescriptor().bindIdValues(value);
@@ -4,7 +4,7 @@ import java.util.Collection;
import java.util.Set;
/**
* Id IN expression common for cache handling.
* ID IN expression common for cache handling.
*/
public interface IdInCommon {
@@ -18,7 +18,7 @@ import java.util.List;
import java.util.Set;
/**
* In a collection of Id values.
* In a collection of ID values.
*/
public final class IdInExpression extends NonPrepareExpression implements IdInCommon {
@@ -73,7 +73,7 @@ public final class IdInExpression extends NonPrepareExpression implements IdInCo
if (idCollection.isEmpty()) {
return;
}
// Bind the Id values including EmbeddedId and multiple Id
// Bind the ID values including EmbeddedId and multiple ID
DefaultExpressionRequest r = (DefaultExpressionRequest) request;
BeanDescriptor<?> descriptor = r.getBeanDescriptor();
@@ -82,7 +82,7 @@ public final class IdInExpression extends NonPrepareExpression implements IdInCo
}
/**
* For use with deleting non attached detail beans during stateless update.
* For use with deleting non-attached detail beans during stateless update.
*/
public void addSqlNoAlias(SpiExpressionRequest request) {
@@ -116,7 +116,7 @@ public final class IdInExpression extends NonPrepareExpression implements IdInCo
}
/**
* Incorporates the number of Id values to bind.
* Incorporates the number of ID values to bind.
*/
@Override
public void queryPlanHash(StringBuilder builder) {
@@ -9,7 +9,6 @@ import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.persist.MultiValueWrapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -54,7 +53,7 @@ final class InPairsExpression extends AbstractExpression {
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
public void writeDocQuery(DocQueryContext context) {
throw new RuntimeException("Not supported with document query");
}
@@ -1,15 +1,10 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.BindValuesKey;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.*;
import io.ebeaninternal.api.SpiQuery.Type;
import io.ebeaninternal.server.query.CQuery;
import java.io.IOException;
import java.util.List;
/**
@@ -42,7 +37,7 @@ final class InQueryExpression extends AbstractExpression implements UnsupportedD
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
public void writeDocQuery(DocQueryContext context) {
throw new IllegalStateException("Not supported");
}
@@ -48,7 +48,7 @@ final class IsEmptyExpression extends AbstractExpression {
}
}
public final String getPropName() {
public String getPropName() {
return propName;
}
@@ -868,7 +868,7 @@ final class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expr
}
@Override
public Query<T> select(FetchGroup fetchGroup) {
public Query<T> select(FetchGroup<T> fetchGroup) {
return exprList.select(fetchGroup);
}
@@ -14,7 +14,7 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import java.io.IOException;
/**
* A logical And or Or for joining two expressions.
* A logical And or, Or for joining two expressions.
*/
abstract class LogicExpression implements SpiExpression {
@@ -1,16 +1,9 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.BindValuesKey;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.NaturalKeyQueryData;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.api.SpiExpressionValidation;
import io.ebeaninternal.api.*;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import java.io.IOException;
/**
* Effectively an expression that has no effect.
*/
@@ -40,7 +33,7 @@ final class NoopExpression implements SpiExpression {
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
public void writeDocQuery(DocQueryContext context) {
}
@Override
@@ -16,7 +16,7 @@ final class RawExpressionBuilder {
*/
static RawExpression buildSingle(String raw, Object value) {
if (isExpand(value, raw, BP_1)) {
Collection val = (Collection) value;
Collection<?> val = (Collection<?>) value;
raw = raw.replace(BP_1, expand(val));
return new RawExpression(raw, val.toArray());
}
@@ -50,8 +50,7 @@ final class RawExpressionBuilder {
return "?" + (i + 1);
}
private static String expand(Collection values) {
private static String expand(Collection<?> values) {
StringBuilder sqlExpand = new StringBuilder(values.size() * 2);
for (int i = 0; i < values.size(); i++) {
if (i > 0) {
@@ -72,7 +71,7 @@ final class RawExpressionBuilder {
if (!isExpand(values[i], raw, match)) {
params.add(values[i]);
} else {
Collection val = (Collection) values[i];
Collection<?> val = (Collection<?>) values[i];
params.addAll(val);
raw = raw.replace(match, expand(val));
}
@@ -10,7 +10,7 @@ import java.util.Objects;
final class Same {
/**
* Return true if both values are null or both an not null.
* Return true if both values are null or both not null.
*/
static boolean sameByNull(Object v1, Object v2) {
return (v1 == null) == (v2 == null);
@@ -55,7 +55,7 @@ public final class SimpleExpression extends AbstractValueExpression {
}
}
public final String getPropName() {
public String getPropName() {
return propName;
}
@@ -21,7 +21,7 @@ Expressions for building WHERE clauses.
<p>
In the code above the LIKE and GREATER THAN Expressions are added to the where clause.
The way this works is that where() returns an ExpressionList which has methods on
it to create the standard expressions (EQUAL TO, LIKE etc).
it to create the standard expressions (EQUAL TO, LIKE etc.)
</p>
<p>
I expect most people to add their expressions in this way. The Expr expression factory
@@ -1,18 +1,5 @@
package io.ebeaninternal.dbmigration;
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringJoiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.avaje.classpath.scanner.core.Location;
import io.ebean.DB;
import io.ebean.Database;
@@ -53,15 +40,22 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlOptions;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.migration.Migration;
import io.ebeaninternal.dbmigration.migrationreader.MigrationXmlWriter;
import io.ebeaninternal.dbmigration.model.CurrentModel;
import io.ebeaninternal.dbmigration.model.MConfiguration;
import io.ebeaninternal.dbmigration.model.MigrationModel;
import io.ebeaninternal.dbmigration.model.ModelContainer;
import io.ebeaninternal.dbmigration.model.ModelDiff;
import io.ebeaninternal.dbmigration.model.PlatformDdlWriter;
import io.ebeaninternal.dbmigration.model.*;
import io.ebeaninternal.extraddl.model.DdlScript;
import io.ebeaninternal.extraddl.model.ExtraDdl;
import io.ebeaninternal.extraddl.model.ExtraDdlXmlReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringJoiner;
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
/**
* Generates DB Migration xml and sql scripts.
@@ -686,6 +680,7 @@ public class DefaultDbMigration implements DbMigration {
if (version == null) {
version = (nextVersion != null) ? nextVersion : initialVersion;
}
checkDropVersion(version, dropsFor);
String fullVersion = applyPrefix + version;
String name = name();
@@ -701,6 +696,13 @@ public class DefaultDbMigration implements DbMigration {
return fullVersion;
}
void checkDropVersion(String version, String dropsFor) {
if (dropsFor != null && dropsFor.equals(version)) {
throw new IllegalArgumentException("The next migration version must not be the same as the pending drops version of " +
dropsFor + ". Please make the next migration version higher than " + dropsFor + ".");
}
}
String trimDropsFor(String dropsFor) {
if (dropsFor.startsWith("V") || dropsFor.startsWith("v")) {
dropsFor = dropsFor.substring(1);
@@ -96,7 +96,7 @@ public class BaseDdlHandler implements DdlHandler {
public void generate(DdlWrite writer, DropTable dropTable) {
tableDdl.generate(writer, dropTable);
}
@Override
public void generate(DdlWrite writer, AlterTable alterTable) {
tableDdl.generate(writer, alterTable);
@@ -194,16 +194,16 @@ public abstract class AbstractHanaDdl extends PlatformDdl {
@Override
protected DdlAlterTable alterTable(DdlWrite writer, String tableName) {
return writer.applyAlterTable(lowerTableName(tableName), HanaAlterTableWrite::new);
return writer.applyAlterTable(tableName, HanaAlterTableWrite::new);
}
/**
* Joins alter table commands and add open/closing brackets for the alter statements
*/
private static class HanaAlterTableWrite extends BaseAlterTableWrite {
class HanaAlterTableWrite extends BaseAlterTableWrite {
public HanaAlterTableWrite(String tableName) {
super(tableName);
super(tableName, AbstractHanaDdl.this);
}
@Override
@@ -17,6 +17,8 @@ public class BaseAlterTableWrite implements DdlAlterTable {
protected static final String RAW_OPERATION = "$RAW";
protected final PlatformDdl platformDdl;
public class AlterCmd {
// the command (e.g. "alter", "modify"
private final String operation;
@@ -58,9 +60,9 @@ public class BaseAlterTableWrite implements DdlAlterTable {
// of all alter commands
target.append(getAlternation());
} else {
target.append("alter table ").append(tableName).append(' ').append(operation);
target.append("alter table ").append(platformDdl.quote(tableName)).append(' ').append(operation);
if (column != null) {
target.append(' ').append(column);
target.append(' ').append(platformDdl.quote(column));
}
if (!getAlternation().isEmpty()) {
target.append(' ').append(getAlternation());
@@ -85,8 +87,9 @@ public class BaseAlterTableWrite implements DdlAlterTable {
private boolean historyHandled;
public BaseAlterTableWrite(String tableName) {
public BaseAlterTableWrite(String tableName, PlatformDdl platformDdl) {
this.tableName = tableName;
this.platformDdl = platformDdl;
}
public String tableName() {
@@ -205,7 +205,7 @@ public class BaseTableDdl implements TableDdl {
public void generate(DdlWrite writer, CreateTable createTable) {
reset();
String tableName = lowerTableName(createTable.getName());
String tableName = createTable.getName();
List<Column> columns = createTable.getColumn();
List<Column> pk = determinePrimaryKeyColumns(columns);
@@ -223,7 +223,7 @@ public class BaseTableDdl implements TableDdl {
String partitionMode = createTable.getPartitionMode();
DdlBuffer apply = writer.apply();
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(lowerTableName(tableName)).append(" (");
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(platformDdl.quote(tableName)).append(" (");
writeTableColumns(apply, columns, identity);
writeUniqueConstraints(apply, createTable);
writeCompoundUniqueConstraints(apply, createTable);
@@ -402,7 +402,7 @@ public class BaseTableDdl implements TableDdl {
protected void writeForeignKey(DdlWrite writer, WriteForeignKey request) {
DdlBuffer fkeyBuffer = writer.applyForeignKeys();
String tableName = lowerTableName(request.table());
String tableName = request.table();
if (request.indexName() != null) {
// no matching unique constraint so add the index
fkeyBuffer.appendStatement(platformDdl.createIndex(new WriteCreateIndex(request.indexName(), tableName, request.cols(), false)));
@@ -427,7 +427,7 @@ public class BaseTableDdl implements TableDdl {
if (i > 0) {
buffer.append(",");
}
buffer.append(lowerColumnName(columns[i].trim()));
buffer.append(platformDdl.quote(columns[i].trim()));
}
buffer.append(")");
}
@@ -494,7 +494,7 @@ public class BaseTableDdl implements TableDdl {
buffer.append(",").newLine();
buffer.append(" constraint ").append(uqName).append(" unique ");
buffer.append("(");
buffer.append(lowerColumnName(column.getName()));
buffer.append(platformDdl.quote(column.getName()));
buffer.append(")");
}
@@ -518,20 +518,6 @@ public class BaseTableDdl implements TableDdl {
return cols;
}
/**
* Convert the table lower case.
*/
protected String lowerTableName(String name) {
return naming.lowerTableName(name);
}
/**
* Convert the column name to lower case.
*/
protected String lowerColumnName(String name) {
return naming.lowerColumnName(name);
}
/**
* Return the list of columns that make the primary key.
*/
@@ -544,7 +530,7 @@ public class BaseTableDdl implements TableDdl {
}
return pk;
}
@Override
public void generate(DdlWrite writer, CreateIndex index) {
if (platformInclude(index.getPlatforms())) {
@@ -775,7 +761,7 @@ public class BaseTableDdl implements TableDdl {
* Return the name of the history table given the base table name.
*/
protected String historyTable(String baseTable) {
return baseTable + historyTableSuffix;
return naming.normaliseTable(baseTable) + historyTableSuffix;
}
/**
@@ -832,6 +818,7 @@ public class BaseTableDdl implements TableDdl {
.appendStatement(platformDdl.alterTableAddCheckConstraint(alter.getTableName(), alter.getCheckConstraintName(), alter.getCheckConstraint()));
}
protected void alterColumnAddForeignKey(DdlWrite writer, AlterColumn alterColumn) {
alterTableAddForeignKey(writer.getOptions(), writer.applyForeignKeys(), new WriteForeignKey(alterColumn));
}
@@ -863,6 +850,7 @@ public class BaseTableDdl implements TableDdl {
writer.dropAllForeignKeys().appendStatement(platformDdl.dropIndex(uqName, alter.getTableName()));
}
protected void alterTableDropColumn(DdlWrite writer, String tableName, String columnName) {
platformDdl.alterTableDropColumn(writer, tableName, columnName);
}
@@ -1,12 +1,12 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
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.AlterColumn;
import io.ebeaninternal.dbmigration.migration.Column;
@@ -62,7 +62,6 @@ 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);
@@ -112,9 +111,10 @@ public class DB2Ddl extends PlatformDdl {
.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("' and tabname = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
.append(" prepare stmt from 'alter table ").append(tableName)
.append(" drop constraint ").append(maxConstraintName(constraintName)).append("';\n")
.append(" execute stmt;\n")
@@ -174,13 +174,13 @@ public class DB2Ddl extends PlatformDdl {
@Override
protected DdlAlterTable alterTable(DdlWrite writer, String tableName) {
return writer.applyAlterTable(lowerTableName(tableName), Db2AlterTableWrite::new);
return writer.applyAlterTable(tableName, Db2AlterTableWrite::new);
};
static class Db2AlterTableWrite extends BaseAlterTableWrite {
class Db2AlterTableWrite extends BaseAlterTableWrite {
public Db2AlterTableWrite(String tableName) {
super(tableName);
super(tableName, DB2Ddl.this);
}
@Override
@@ -1,14 +1,12 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import java.util.Collection;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
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;
/**
@@ -22,6 +20,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
private String systemPeriodEnd;
private String transactionId;
private PlatformDdl platformDdl;
private DbConstraintNaming constraintNaming;
private String historySuffix;
@Override
@@ -30,36 +29,21 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
this.transactionId = config.getAsOfSysPeriod() + "_txn"; // required for DB2
this.platformDdl = platformDdl;
this.constraintNaming = config.getConstraintNaming();
this.historySuffix = config.getHistoryTableSuffix();
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) {
String tableName = table.getName();
String historyTableName = tableName + historySuffix;
String historyTableName = historyTable(tableName);
DdlBuffer apply = writer.applyPostAlter();
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ")
.append(platformDdl.lowerTableName(historyTableName)).append(" (").newLine();
// create history table
Collection<MColumn> 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
// DB2 requires an EXACT copy (same column types with null/non-null, same order)
addSysPeriodColumns(writer, tableName);
enableSystemVersioning(apply, tableName);
writer.applyPostAlter().append("create table ").append(historyTableName)
.append(" as (select * from ").append(tableName).append(") with no data").endOfStatement();
enableSystemVersioning(writer.applyPostAlter(), tableName);
platformDdl.alterTable(writer, tableName).setHistoryHandled();
// drop all: We do not drop columns here, as the whole table will be dropped
@@ -77,10 +61,10 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
dropHistoryTable(writer, dropHistoryTable.getBaseTable(), dropHistoryTable.getBaseTable() + historySuffix);
dropHistoryTable(writer, dropHistoryTable.getBaseTable());
}
protected void dropHistoryTable(DdlWrite writer, String baseTable, String historyTable) {
protected void dropHistoryTable(DdlWrite writer, String baseTable) {
disableSystemVersioning(writer.apply(), baseTable);
writer.apply().append("alter table ").append(baseTable).append(" drop period system_time").endOfStatement();
@@ -90,7 +74,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
platformDdl.alterTableDropColumn(writer, baseTable, transactionId);
// drop the history table
writer.applyPostAlter().append("drop table ").append(historyTable).endOfStatement();
writer.applyPostAlter().append("drop table ").append(historyTable(baseTable)).endOfStatement();
}
@Override
@@ -118,22 +102,16 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
}
}
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();
apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(historyTable(tableName)).endOfStatement();
}
protected String historyTable(String tableName) {
return constraintNaming.normaliseTable(tableName) + historySuffix;
}
}
@@ -127,11 +127,15 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
protected String historyTableName(String baseTableName) {
return baseTableName + historySuffix;
return quote(normalise(baseTableName) + historySuffix);
}
protected String historyViewName(String baseTableName) {
return quote(normalise(baseTableName) + viewSuffix);
}
protected String procedureName(String baseTableName) {
return baseTableName + "_history_version";
return normalise(baseTableName) + "_history_version";
}
protected String triggerName(String baseTableName) {
@@ -146,16 +150,6 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
return normalise(baseTableName) + "_history_del";
}
protected void addHistoryTable(DdlWrite writer, MTable table, String whenCreatedColumn) {
String baseTableName = table.getName();
addSysPeriodColumns(writer, baseTableName, whenCreatedColumn);
createHistoryTable(writer.applyPostAlter(), table);
createWithHistoryView(writer.applyPostAlter(), baseTableName);
}
protected void addSysPeriodColumns(DdlWrite writer, String baseTableName, String whenCreatedColumn) {
platformDdl.alterTableAddColumn(writer, baseTableName, sysPeriodStart, sysPeriodType, now);
@@ -172,14 +166,17 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
protected void createHistoryTableAs(DdlBuffer apply, MTable table) {
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ")
.append(platformDdl.lowerTableName(table.getName() + historySuffix)).append("(").newLine();
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(historyTableName(table.getName())).append("(").newLine();
for (MColumn column : table.allColumns()) {
if (!column.isDraftOnly()) {
writeColumnDefinition(apply, column.getName(), column.getType());
apply.append(",").newLine();
}
}
// TODO: We must apply also pending dropped columns. Let's do that in a later step
if (table.hasDroppedColumns()) {
throw new IllegalStateException(table.getName() + " has dropped columns. Please generate drop script before enabling history");
}
}
protected void createHistoryTableWithPeriod(DdlBuffer apply) {
@@ -196,16 +193,16 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
String platformType = platformDdl.convert(type);
buffer.append(" ");
buffer.append(platformDdl.lowerColumnName(columnName), 29);
buffer.append(quote(columnName), 29);
buffer.append(platformType);
}
protected void createWithHistoryView(DdlBuffer apply, String baseTableName) {
apply
.append("create view ").append(platformDdl.lowerTableName(baseTableName)).append(viewSuffix)
.append(" as select * from ").append(platformDdl.lowerTableName(baseTableName))
.append(" union all select * from ").append(platformDdl.lowerTableName(baseTableName + historySuffix))
.append("create view ").append(historyViewName(baseTableName))
.append(" as select * from ").append(quote(baseTableName))
.append(" union all select * from ").append(historyTableName(baseTableName))
.endOfStatement();
}
@@ -215,11 +212,11 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
protected void dropWithHistoryView(DdlBuffer apply, String baseTableName) {
apply.append("drop view ").append(platformDdl.lowerTableName(baseTableName + viewSuffix)).endOfStatement();
apply.append("drop view ").append(historyViewName(baseTableName)).endOfStatement();
}
protected void dropHistoryTable(DdlBuffer apply, String baseTableName) {
apply.append("drop table ").append(platformDdl.lowerTableName(baseTableName + historySuffix)).endOfStatement().end();
apply.append("drop table ").append(historyTableName(baseTableName)).endOfStatement().end();
}
protected void dropSysPeriodColumns(DdlWrite writer, String baseTableName) {
@@ -229,8 +226,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected void appendInsertIntoHistory(DdlBuffer buffer, String baseTable, List<String> columns) {
buffer.append(" insert into ").append(platformDdl.lowerTableName(baseTable + historySuffix))
.append(" (").append(sysPeriodStart).append(",").append(sysPeriodEnd).append(",");
buffer.append(" insert into ").append(historyTableName(baseTable)).append(" (").append(sysPeriodStart).append(",").append(sysPeriodEnd).append(",");
appendColumnNames(buffer, columns, "");
buffer.append(") values (OLD.").append(sysPeriodStart).append(", ").append(sysPeriodEndValue).append(",");
appendColumnNames(buffer, columns, "OLD.");
@@ -272,4 +268,8 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
public boolean alterHistoryTables() {
return true;
}
protected String quote(String dbName) {
return platformDdl.quote(dbName);
}
}
@@ -31,7 +31,7 @@ public class H2HistoryDdl extends DbTriggerBasedHistoryDdl {
// Note that this does not take into account the historyTable name (excepts _history suffix) and
// does not take into account excluded columns (all columns included in history)
apply
.append("create trigger ").append(triggerName).append(" before update,delete on ").append(baseTable)
.append("create trigger ").append(triggerName).append(" before update,delete on ").append(quote(baseTable))
.append(" for each row call \"" + TRIGGER_CLASS + "\";").newLine();
}
@@ -1,6 +1,7 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
@@ -16,6 +17,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
private String systemPeriodStart;
private String systemPeriodEnd;
private PlatformDdl platformDdl;
private DbConstraintNaming constraintNaming;
private String historySuffix;
@Override
@@ -23,17 +25,17 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
this.systemPeriodStart = config.getAsOfSysPeriod() + "_start";
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
this.platformDdl = platformDdl;
this.constraintNaming = config.getConstraintNaming();
this.historySuffix = config.getHistoryTableSuffix();
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) {
String tableName = table.getName();
String historyTableName = tableName + historySuffix;
String historyTableName = historyTableName(tableName);
DdlBuffer apply = writer.applyPostAlter();
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ")
.append(platformDdl.lowerTableName(historyTableName)).append(" (").newLine();
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(historyTableName).append(" (").newLine();
// create history table
Collection<MColumn> cols = table.allColumns();
@@ -67,7 +69,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
dropHistoryTable(writer.applyDropDependencies(), dropHistoryTable.getBaseTable(),
dropHistoryTable.getBaseTable() + historySuffix);
historyTableName(dropHistoryTable.getBaseTable()));
}
protected void dropHistoryTable(DdlBuffer apply, String baseTable, String historyTable) {
@@ -113,7 +115,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
boolean isNotNull, String generated) {
String platformType = platformDdl.convert(type);
buffer.append(" ").append(platformDdl.lowerColumnName(columnName));
buffer.append(" ").append(columnName);
buffer.append(" ").append(platformType);
if (defaultValue != null) {
buffer.append(" default ").append(defaultValue);
@@ -127,16 +129,19 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
public void disableSystemVersioning(DdlBuffer apply, String tableName) {
apply.append("alter table ").append(platformDdl.lowerTableName(tableName)).append(" drop system versioning").endOfStatement();
apply.append("alter table ").append(tableName).append(" drop system versioning").endOfStatement();
}
public void enableSystemVersioning(DdlBuffer apply, String tableName, boolean validated) {
apply.append("alter table ").append(platformDdl.lowerTableName(tableName))
.append(" add system versioning history table ").append(platformDdl.lowerTableName(tableName + historySuffix));
apply.append("alter table ").append(tableName).append(" add system versioning history table ").append(historyTableName(tableName));
if (!validated) {
apply.append(" not validated");
}
apply.endOfStatement();
}
protected String historyTableName(String tableName) {
return constraintNaming.normaliseTable(tableName) + historySuffix;
}
}
@@ -32,13 +32,14 @@ public class MySqlDdl extends PlatformDdl {
*/
@Override
public String dropIndex(String indexName, String tableName, boolean concurrent) {
return "drop index " + maxConstraintName(indexName) + " on " + tableName;
return "drop index " + maxConstraintName(indexName) + " on " + quote(tableName);
}
@Override
public void alterTableDropColumn(DdlWrite writer, String tableName, String columnName) {
if (this.useMigrationStoredProcedures) {
alterTable(writer, tableName).raw("CALL usp_ebean_drop_column('").append(tableName).append("', '").append(columnName).append("')");
alterTable(writer, tableName).raw("CALL usp_ebean_drop_column('").append(naming.normaliseTable(tableName))
.append("', '").append(naming.normaliseColumn(columnName)).append("')");
} else {
super.alterTableDropColumn(writer, tableName, columnName);
}
@@ -49,7 +50,7 @@ public class MySqlDdl extends PlatformDdl {
*/
@Override
public String alterTableDropForeignKey(String tableName, String fkName) {
return "alter table " + tableName + " drop foreign key " + maxConstraintName(fkName);
return "alter table " + quote(tableName) + " drop foreign key " + maxConstraintName(fkName);
}
@Override
@@ -146,7 +147,7 @@ public class MySqlDdl extends PlatformDdl {
if (DdlHelp.isDropComment(tableComment)) {
tableComment = "";
}
apply.append(String.format("alter table %s comment = '%s'", tableName, tableComment)).endOfStatement();
apply.append(String.format("alter table %s comment = '%s'", quote(tableName), tableComment)).endOfStatement();
}
@Override
@@ -20,12 +20,17 @@ import io.ebeaninternal.dbmigration.model.MTable;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Controls the DDL generation for a specific database platform.
*/
public class PlatformDdl {
// matches on pattern "check ( COLUMNAME ... )". ColumnName is match group 2;
private static final Pattern CHECK_PATTERN = Pattern.compile("(.*?\\( *)([^ ]+)(.*)");
protected final DatabasePlatform platform;
protected PlatformHistoryDdl historyDdl = new NoHistorySupportDdl();
@@ -119,7 +124,7 @@ public class PlatformDdl {
protected boolean inlineForeignKeys;
protected boolean includeStorageEngine;
protected final DbDefaultValue dbDefaultValue;
protected String fallbackArrayType = "varchar(1000)";
@@ -258,7 +263,7 @@ public class PlatformDdl {
}
buffer.append(" ");
buffer.append(lowerColumnName(column.getName()), 29);
buffer.append(quote(column.getName()), 29);
buffer.append(columnDefn);
if (!Boolean.TRUE.equals(column.isPrimaryKey())) {
String defaultValue = convertDefaultValue(column.getDefaultValue());
@@ -278,7 +283,7 @@ public class PlatformDdl {
* Returns the check constraint.
*/
public String createCheckConstraint(String ckName, String checkConstraint) {
return " constraint " + ckName + " " + checkConstraint;
return " constraint " + maxConstraintName(ckName) + " " + quoteCheckConstraint(checkConstraint);
}
/**
@@ -292,7 +297,7 @@ public class PlatformDdl {
* Return the drop foreign key clause.
*/
public String alterTableDropForeignKey(String tableName, String fkName) {
return "alter table " + alterTableIfExists + lowerTableName(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(fkName);
return "alter table " + alterTableIfExists + quote(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(fkName);
}
/**
@@ -372,7 +377,7 @@ public class PlatformDdl {
*/
public String createSequence(String sequenceName, DdlIdentity identity) {
StringBuilder sb = new StringBuilder("create sequence ");
sb.append(sequenceName);
sb.append(quote(sequenceName));
sb.append(identity.sequenceOptions(sequenceStartWith, sequenceIncrementBy, sequenceCache));
sb.append(";");
return sb.toString();
@@ -382,14 +387,14 @@ public class PlatformDdl {
* Return the drop sequence statement (potentially with if exists clause).
*/
public String dropSequence(String sequenceName) {
return dropSequenceIfExists + sequenceName;
return dropSequenceIfExists + quote(sequenceName);
}
/**
* Return the drop table statement (potentially with if exists clause).
*/
public String dropTable(String tableName) {
return dropTableIfExists + lowerTableName(tableName) + dropTableCascade;
return dropTableIfExists + quote(tableName) + dropTableCascade;
}
/**
@@ -405,7 +410,7 @@ public class PlatformDdl {
public String dropIndex(String indexName, String tableName, boolean concurrent) {
return dropIndexIfExists + maxConstraintName(indexName);
}
public String createIndex(WriteCreateIndex create) {
if (create.useDefinition()) {
return create.getDefinition();
@@ -422,7 +427,7 @@ public class PlatformDdl {
if (create.isNotExistsCheck()) {
buffer.append(createIndexIfNotExists);
}
buffer.append(maxConstraintName(create.getIndexName())).append(" on ").append(lowerTableName(create.getTableName()));
buffer.append(maxConstraintName(create.getIndexName())).append(" on ").append(quote(create.getTableName()));
appendColumns(create.getColumns(), buffer);
return buffer.toString();
}
@@ -435,7 +440,7 @@ public class PlatformDdl {
StringBuilder buffer = new StringBuilder(90);
buffer.append("foreign key");
appendColumns(request.cols(), buffer);
buffer.append(" references ").append(lowerTableName(request.refTable()));
buffer.append(" references ").append(quote(request.refTable()));
appendColumns(request.refCols(), buffer);
appendForeignKeySuffix(request, buffer);
return buffer.toString();
@@ -448,13 +453,13 @@ public class PlatformDdl {
StringBuilder buffer = new StringBuilder(90);
buffer
.append("alter table ").append(lowerTableName(request.table()))
.append("alter table ").append(quote(request.table()))
.append(" add constraint ").append(maxConstraintName(request.fkName()))
.append(" foreign key");
appendColumns(request.cols(), buffer);
buffer
.append(" references ")
.append(lowerTableName(request.refTable()));
.append(quote(request.refTable()));
appendColumns(request.refCols(), buffer);
appendForeignKeySuffix(request, buffer);
if (options.isForeignKeySkipCheck()) {
@@ -503,14 +508,14 @@ public class PlatformDdl {
* Drop a unique constraint from the table (Sometimes this is an index).
*/
public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) {
return "alter table " + lowerTableName(tableName) + " " + dropUniqueConstraint + " " + maxConstraintName(uniqueConstraintName);
return "alter table " + quote(tableName) + " " + dropUniqueConstraint + " " + maxConstraintName(uniqueConstraintName);
}
/**
* Drop a unique constraint from the table.
*/
public String alterTableDropConstraint(String tableName, String constraintName) {
return "alter table " + lowerTableName(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(constraintName);
return "alter table " + quote(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(constraintName);
}
/**
@@ -528,7 +533,7 @@ public class PlatformDdl {
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
StringBuilder buffer = new StringBuilder(90);
buffer.append("alter table ").append(tableName).append(" add constraint ").append(maxConstraintName(uqName)).append(" unique ");
buffer.append("alter table ").append(quote(tableName)).append(" add constraint ").append(maxConstraintName(uqName)).append(" unique ");
appendColumns(columns, buffer);
return buffer.toString();
}
@@ -619,9 +624,10 @@ public class PlatformDdl {
* Alter table adding the check constraint.
*/
public String alterTableAddCheckConstraint(String tableName, String checkConstraintName, String checkConstraint) {
return "alter table " + lowerTableName(tableName) + " " + addConstraint + " " + maxConstraintName(checkConstraintName) + " " + checkConstraint;
return "alter table " + quote(tableName) + " " + addConstraint + " " + maxConstraintName(checkConstraintName) + " " + quoteCheckConstraint(checkConstraint);
}
/**
* Alter column setting the default value.
* <p>
@@ -663,7 +669,7 @@ public class PlatformDdl {
* Creates or replace a new DdlAlterTable for given tableName.
*/
protected DdlAlterTable alterTable(DdlWrite writer, String tableName) {
return writer.applyAlterTable(lowerTableName(tableName), BaseAlterTableWrite::new);
return writer.applyAlterTable(tableName, k -> new BaseAlterTableWrite(k, this));
}
protected void appendColumns(String[] columns, StringBuilder buffer) {
@@ -672,31 +678,11 @@ public class PlatformDdl {
if (i > 0) {
buffer.append(",");
}
buffer.append(lowerColumnName(columns[i].trim()));
buffer.append(quote(columns[i].trim()));
}
buffer.append(")");
}
/**
* Convert the table to lower case.
* <p>
* Override as desired. Generally lower case with underscore is a good cross database
* choice for column/table names.
*/
protected String lowerTableName(String name) {
return naming.lowerTableName(name);
}
/**
* Convert the column name to lower case.
* <p>
* Override as desired. Generally lower case with underscore is a good cross database
* choice for column/table names.
*/
protected String lowerColumnName(String name) {
return naming.lowerColumnName(name);
}
public DatabasePlatform getPlatform() {
return platform;
}
@@ -740,7 +726,7 @@ public class PlatformDdl {
if (DdlHelp.isDropComment(tableComment)) {
tableComment = "";
}
apply.append(String.format("comment on table %s is '%s'", tableName, tableComment)).endOfStatement();
apply.append(String.format("comment on table %s is '%s'", quote(tableName), tableComment)).endOfStatement();
}
/**
@@ -750,7 +736,7 @@ public class PlatformDdl {
if (DdlHelp.isDropComment(comment)) {
comment = "";
}
apply.append(String.format("comment on column %s.%s is '%s'", table, column, comment)).endOfStatement();
apply.append(String.format("comment on column %s.%s is '%s'", quote(table), quote(column), comment)).endOfStatement();
}
/**
@@ -813,4 +799,16 @@ public class PlatformDdl {
// now only supported for db2
}
protected String quote(String dbName) {
return platform.convertQuotedIdentifiers(dbName);
}
protected String quoteCheckConstraint(String checkConstraint) {
Matcher matcher = CHECK_PATTERN.matcher(checkConstraint);
if (matcher.matches()) {
return matcher.replaceFirst("$1" + quote(matcher.group(2)) + "$3");
}
return checkConstraint;
}
}
@@ -21,8 +21,8 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
*/
@Override
protected void createHistoryTable(DdlBuffer apply, MTable table) {
apply.append("create table ").append(platformDdl.lowerTableName(table.getName() + historySuffix))
.append("(like ").append(platformDdl.lowerTableName(table.getName())).append(")").endOfStatement();
apply.append("create table ").append(historyTableName(table.getName()))
.append("(like ").append(table.getName()).append(")").endOfStatement();
}
/**
@@ -33,8 +33,8 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
platformDdl.alterTableAddColumn(writer, baseTableName, sysPeriod, "tstzrange not null", "tstzrange(" + now + ", null)");
if (whenCreatedColumn != null) {
writer.applyPostAlter()
.append("update ").append(platformDdl.lowerTableName(baseTableName)).append(" set ")
.append(sysPeriod).append(" = tstzrange(").append(platformDdl.lowerColumnName(whenCreatedColumn)).append(", null)").endOfStatement();
.append("update ").append(baseTableName).append(" set ")
.append(sysPeriod).append(" = tstzrange(").append(whenCreatedColumn).append(", null)").endOfStatement();
}
}
@@ -55,15 +55,14 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
createOrReplaceFunction(buffer, procedureName, historyTableName(baseTableName), columnNames);
buffer
.append("create trigger ").append(triggerName).newLine()
.append(" before update or delete on ").append(platformDdl.lowerTableName(baseTableName)).newLine()
.append(" before update or delete on ").append(baseTableName).newLine()
.append(" for each row execute procedure ").append(procedureName).append("();").newLine().newLine();
}
@Override
protected void dropTriggers(DdlBuffer buffer, String baseTable) {
// rollback trigger then function
buffer.append("drop trigger if exists ").append(triggerName(baseTable)).append(" on ")
.append(platformDdl.lowerTableName(baseTable)).append(" cascade").endOfStatement();
buffer.append("drop trigger if exists ").append(triggerName(baseTable)).append(" on ").append(baseTable).append(" cascade").endOfStatement();
buffer.append("drop function if exists ").append(procedureName(baseTable)).append("()").endOfStatement();
buffer.end();
}
@@ -101,7 +100,7 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
@Override
protected void appendInsertIntoHistory(DdlBuffer buffer, String historyTable, List<String> columns) {
buffer.append(" insert into ").append(platformDdl.lowerTableName(historyTable)).append(" (").append(sysPeriod).append(",");
buffer.append(" insert into ").append(historyTable).append(" (").append(sysPeriod).append(",");
appendColumnNames(buffer, columns, "");
buffer.append(") values (tstzrange(lowerTs,upperTs), ");
appendColumnNames(buffer, columns, "OLD.");
@@ -65,12 +65,12 @@ public class SQLiteDdl extends PlatformDdl {
@Override
protected DdlAlterTable alterTable(DdlWrite writer, String tableName) {
return writer.applyAlterTable(lowerTableName(tableName), SQLiteAlterTableWrite::new);
return writer.applyAlterTable(tableName, SQLiteAlterTableWrite::new);
}
static class SQLiteAlterTableWrite extends BaseAlterTableWrite {
class SQLiteAlterTableWrite extends BaseAlterTableWrite {
public SQLiteAlterTableWrite(String tableName) {
super(tableName);
super(tableName, SQLiteDdl.this);
}
@Override
@@ -72,7 +72,6 @@ public class SqlServerDdl extends PlatformDdl {
throw new NullPointerException();
}
// issues#233
StringBuilder sb = new StringBuilder(256);
sb.append("create unique nonclustered index ").append(uqName).append(" on ").append(tableName).append('(');
for (int i = 0; i < columns.length; i++) {
@@ -1,6 +1,7 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
@@ -17,12 +18,17 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
private String systemPeriodStart;
private String systemPeriodEnd;
private PlatformDdl platformDdl;
protected DbConstraintNaming constraintNaming;
protected String historySuffix;
@Override
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
this.systemPeriodStart = config.getAsOfSysPeriod() + "From";
this.systemPeriodEnd = config.getAsOfSysPeriod() + "To";
this.platformDdl = platformDdl;
this.constraintNaming = config.getConstraintNaming();
this.historySuffix = config.getHistoryTableSuffix();
}
@Override
@@ -31,31 +37,21 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
enableSystemVersioning(writer, baseTable);
}
String getHistoryTable(String baseTable) {
String historyTable = baseTable + "_history";
if (baseTable.startsWith("[")) {
historyTable = historyTable.replace("]", "") + "]";
}
if (historyTable.indexOf('.') == -1) {
// history must contain schema, add the default schema if none was specified
historyTable = "dbo." + historyTable;
}
return historyTable;
}
private void enableSystemVersioning(DdlWrite writer, String baseTable) {
DdlBuffer apply = writer.applyPostAlter();
apply.append("alter table ").append(baseTable).newLine()
apply.append("alter table ").append(quote(baseTable)).newLine()
.append(" add ").append(systemPeriodStart).append(" datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(),").newLine()
.append(" ").append(systemPeriodEnd).append(" datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999',").newLine()
.append("period for system_time (").append(systemPeriodStart).append(", ").append(systemPeriodEnd).append(")").endOfStatement();
apply.append("alter table ").append(baseTable).append(" set (system_versioning = on (history_table=")
.append(getHistoryTable(baseTable)).append("))").endOfStatement();
.append(historyTableWithSchema(baseTable)).append("))").endOfStatement();
DdlBuffer drop = writer.dropAll();
drop.append("IF OBJECT_ID('").append(baseTable).append("', 'U') IS NOT NULL alter table ").append(baseTable).append(" set (system_versioning = off)").endOfStatement();
drop.append("IF OBJECT_ID('").append(baseTable).append("_history', 'U') IS NOT NULL drop table ").append(baseTable).append("_history").endOfStatement();
drop.append("IF OBJECT_ID('").append(quote(baseTable)).append("', 'U') IS NOT NULL alter table ")
.append(quote(baseTable)).append(" set (system_versioning = off)").endOfStatement();
drop.append("IF OBJECT_ID('").append(historyTableName(baseTable)).append("', 'U') IS NOT NULL drop table ")
.append(historyTableName(baseTable)).endOfStatement();
}
@Override
@@ -73,13 +69,13 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
// switch of versioning & period - must be done before altering
DdlBuffer apply = writer.apply();
apply.append("-- dropping history support for ").append(baseTable).endOfStatement();
apply.append("alter table ").append(baseTable).append(" set (system_versioning = off)").endOfStatement();
apply.append("alter table ").append(baseTable).append(" drop period for system_time").endOfStatement();
apply.append("alter table ").append(quote(baseTable)).append(" set (system_versioning = off)").endOfStatement();
apply.append("alter table ").append(quote(baseTable)).append(" drop period for system_time").endOfStatement();
apply.end();
// now drop tables & columns, they will go to alter table/post alter buffers
platformDdl.alterTableDropColumn(writer, baseTable, systemPeriodStart);
platformDdl.alterTableDropColumn(writer, baseTable, systemPeriodEnd);
writer.applyPostAlter().appendStatement(platformDdl.dropTable(baseTable + "_history"));
writer.applyPostAlter().appendStatement(platformDdl.dropTable(historyTableName(baseTable)));
}
@Override
@@ -95,13 +91,36 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
if (!alter.isHistoryHandled()) {
// SQL Server 2016 does not need triggers
DdlBuffer apply = writer.apply();
apply.append("-- alter table ").append(tableName).append(" set (system_versioning = off (history_table=")
.append(getHistoryTable(tableName)).append("))").endOfStatement();
apply.append("-- alter table ").append(quote(tableName)).append(" set (system_versioning = off (history_table=")
.append(historyTableWithSchema(tableName)).append("))").endOfStatement();
apply.append("-- history migration goes here").newLine();
apply.append("-- alter table ").append(tableName).append(" set (system_versioning = on (history_table=")
.append(getHistoryTable(tableName)).append("))").endOfStatement();
apply.append("-- alter table ").append(quote(tableName)).append(" set (system_versioning = on (history_table=")
.append(historyTableWithSchema(tableName)).append("))").endOfStatement();
}
alter.setHistoryHandled();
}
protected String quote(String baseTable) {
return platformDdl.quote(baseTable);
}
protected String normalise(String tableName) {
return constraintNaming.normaliseTable(tableName);
}
protected String historyTableName(String baseTableName) {
return normalise(baseTableName) + historySuffix;
}
protected String historyTableWithSchema(String baseTableName) {
String historyTable = historyTableName(baseTableName);
int lastPeriod = baseTableName.lastIndexOf('.');
if (lastPeriod == -1) {
// history must contain schema, add the default schema if none was specified
return "dbo." + historyTable;
} else {
return baseTableName.substring(0, lastPeriod + 1) + historyTable;
}
}
}
@@ -309,7 +309,7 @@ public class MTable {
if (localColumn == null) {
// can ignore if draftOnly column and non-draft table
if (!newColumn.isDraftOnly() || draft) {
diffNewColumn(newColumn);
diffNewColumn(newColumn, newTable);
}
} else {
localColumn.compare(modelDiff, this, newColumn);
@@ -509,6 +509,13 @@ public class MTable {
return columnNames;
}
/**
* Returns true, if there are pending dropped columns.
*/
public boolean hasDroppedColumns() {
return !droppedColumns.isEmpty();
}
/**
* Return all the columns (excluding columns marked as dropped).
*/
@@ -628,11 +635,11 @@ public class MTable {
/**
* Add a 'new column' to the AddColumn migration object.
*/
private void diffNewColumn(MColumn newColumn) {
private void diffNewColumn(MColumn newColumn, MTable newTable) {
if (addColumn == null) {
addColumn = new AddColumn();
addColumn.setTableName(name);
if (withHistory) {
if (newTable.isWithHistory()) {
// These addColumns need to occur on the history
// table as well as the base table
addColumn.setWithHistory(Boolean.TRUE);
@@ -424,9 +424,7 @@ public class ModelContainer {
for (Object change : changeSet.getChangeSetChildren()) {
if (change instanceof DropColumn) {
DropColumn dropColumn = (DropColumn) change;
if (Boolean.TRUE.equals(dropColumn.isWithHistory())) {
registerPendingDropColumn(dropColumn);
}
registerPendingDropColumn(dropColumn);
}
}
}
@@ -3,13 +3,14 @@ package io.ebeaninternal.dbmigration;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DefaultDbMigrationTest {
class DefaultDbMigrationTest {
private final DefaultDbMigration migration = new DefaultDbMigration();
@Test
public void trimDropsFor() {
void trimDropsFor() {
assertEquals("1.2", migration.trimDropsFor("V1.2__hello"));
assertEquals("1.2", migration.trimDropsFor("v1.2__hello"));
assertEquals("1.2", migration.trimDropsFor("v1.2"));
@@ -17,4 +18,16 @@ public class DefaultDbMigrationTest {
assertEquals("junk1.2", migration.trimDropsFor("junk1.2__"));
assertEquals("junk1.2", migration.trimDropsFor("junk1.2__more"));
}
@Test
void checkDropVersion_when_matches_throwsIAE() {
assertThrows(IllegalArgumentException.class, () -> migration.checkDropVersion("1.0", "1.0"));
}
@Test
void checkDropVersion_ok() {
migration.checkDropVersion("1.0", null);
migration.checkDropVersion("1.0", "1.0.0");
migration.checkDropVersion("1.0", "1.1");
}
}
@@ -2,6 +2,9 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import org.junit.jupiter.api.Test;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import static org.assertj.core.api.Assertions.assertThat;
public class SqlServerHistoryDdlTest {
@@ -10,8 +13,12 @@ public class SqlServerHistoryDdlTest {
public void getHistoryTable() {
SqlServerHistoryDdl ddl = new SqlServerHistoryDdl();
assertThat(ddl.getHistoryTable("foo")).isEqualTo("dbo.foo_history");
assertThat(ddl.getHistoryTable("bar.foo")).isEqualTo("bar.foo_history");
assertThat(ddl.getHistoryTable("[Foo]")).isEqualTo("dbo.[Foo_history]");
ddl.configure(new DatabaseConfig(), new SqlServerDdl(new SqlServer17Platform()));
assertThat(ddl.historyTableWithSchema("foo")).isEqualTo("dbo.foo_history");
assertThat(ddl.historyTableWithSchema("bar.foo")).isEqualTo("bar.foo_history");
// test with reserved keywords in quotes
assertThat(ddl.historyTableWithSchema("[select]")).isEqualTo("dbo.select_history");
assertThat(ddl.historyTableWithSchema("\"select\"")).isEqualTo("dbo.select_history");
assertThat(ddl.historyTableWithSchema("`select`")).isEqualTo("dbo.select_history");
}
}
@@ -1,11 +1,11 @@
create table persons (
id bigint generated by default as identity (start with 1000 increment by 40) not null,
surname varchar(64) not null,
name varchar(64) not null,
constraint pk_persons primary key (id)
create table PERSONS (
ID bigint generated by default as identity (start with 1000 increment by 40) not null,
SURNAME varchar(64) not null,
NAME varchar(64) not null,
constraint pk_persons primary key (ID)
);
create table phones (
create table PHONES (
id bigint generated by default as identity not null,
phone_number varchar(7) not null,
person_id bigint not null,
@@ -14,6 +14,6 @@ create table phones (
);
-- foreign keys and indices
create index ix_phones_person_id on phones (person_id);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
create index ix_phones_person_id on PHONES (person_id);
alter table PHONES add constraint fk_phones_person_id foreign key (person_id) references PERSONS (ID) on delete restrict on update restrict;
@@ -1,11 +1,11 @@
create table persons (
id bigint generated by default as identity (start with 1000 increment by 40) not null,
surname varchar(64) not null,
name varchar(64) not null,
constraint pk_persons primary key (id)
create table PERSONS (
ID bigint generated by default as identity (start with 1000 increment by 40) not null,
SURNAME varchar(64) not null,
NAME varchar(64) not null,
constraint pk_persons primary key (ID)
);
create table phones (
create table PHONES (
id bigint generated by default as identity not null,
phone_number varchar(7) not null,
person_id bigint not null,
@@ -14,6 +14,6 @@ create table phones (
);
-- foreign keys and indices
create index ix_phones_person_id on phones (person_id);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict not valid;
create index ix_phones_person_id on PHONES (person_id);
alter table PHONES add constraint fk_phones_person_id foreign key (person_id) references PERSONS (ID) on delete restrict on update restrict not valid;
@@ -33,10 +33,6 @@ public class DbConstraintNamingTest {
@Test
public void testDefaultToLower() {
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
}
@Test
@@ -44,11 +40,7 @@ public class DbConstraintNamingTest {
DbConstraintNaming naming = new DbConstraintNaming(false, true);
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("FOO_BAR");
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("sch.foo_bar");
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
// table name not lowered
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("SCH.FOO_BAR");
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
}
@Test
@@ -56,11 +48,7 @@ public class DbConstraintNamingTest {
DbConstraintNaming naming = new DbConstraintNaming(true, false);
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR");
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
// column name not lowered
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("SCH.FOO_BAR");
}
@Test
@@ -6,6 +6,7 @@ import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DbHistorySupport;
import io.ebean.datasource.pool.ConnectionPool;
import misc.migration.v1_0.ETable;
import misc.migration.v1_1.EHistory;
import misc.migration.v1_1.EHistory2;
import org.junit.jupiter.api.Test;
@@ -84,7 +85,10 @@ public class DbMigrationTest extends BaseTestCase {
"migtest_mtm_c_migtest_mtm_m",
"migtest_mtm_m_migtest_mtm_c",
"migtest_oto_child",
"migtest_oto_master");
"migtest_oto_master",
"table",
"\"table\"",
"`table`");
((ConnectionPool)server().dataSource()).offline();
((ConnectionPool)server().dataSource()).online();
@@ -117,7 +121,7 @@ public class DbMigrationTest extends BaseTestCase {
assertThat(server().execute(update)).isEqualTo(2);
}
testReservedKeywords();
createHistoryEntities();
if (isOracle()) {
// Oracle does not like to convert varchar to integer
@@ -262,6 +266,32 @@ public class DbMigrationTest extends BaseTestCase {
}
}
// do some history tests with V1.1 models
private void testReservedKeywords() {
DatabaseConfig config = new DatabaseConfig();
config.setName(server().name());
config.loadFromProperties(server().pluginApi().config().getProperties());
config.setDataSource(server().dataSource());
config.setReadOnlyDataSource(server().dataSource());
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setRegister(false);
config.setPackages(Collections.singletonList("misc.migration.v1_0"));
Database tmpServer = DatabaseFactory.create(config);
try {
ETable table = new misc.migration.v1_0.ETable();
table.setFrom("foo");
table.setTo("bar");
table.setIndex("id");
tmpServer.save(table);
table = tmpServer.find(ETable.class).where().eq("index", "id").findOne();
assert table != null;
} finally {
tmpServer.shutdown(false, false);
}
}
private void createHistoryEntities() {
SqlUpdate update = server().sqlUpdate("insert into migtest_e_history (id, test_string) values (1, '42')");
assertThat(server().execute(update)).isEqualTo(1);
@@ -0,0 +1,90 @@
package misc.migration.v1_0;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History
public class ETable {
@Column(name = "`index`")
@DbComment("this is a comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getVarchar() {
return varchar;
}
public void setVarchar(String varchar) {
this.varchar = varchar;
}
public ETable getForeign() {
return foreign;
}
public void setForeign(ETable foreign) {
this.foreign = foreign;
}
public List<ETable> getForeigns() {
return foreigns;
}
}
@@ -0,0 +1,49 @@
package misc.migration.v1_1;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History // FIXME: remove later
public class ETable {
@Column(name = "`index`")
@DbComment("this is an other comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
@Column(name = "`select`")
@Index(unique = true)
private String select;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
}
@@ -0,0 +1,55 @@
package misc.migration.v1_2;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History
public class ETable {
@Column(name = "`index`")
@DbComment("this is a comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
// Note: This column should be removed, (as it is also not present in V1.0)
// There is a limitation in history generation, that you cannot enable history while you have pending drops
// History-table will be generyted in V1.3 - SQL without that column, while base table still contains that column
// When creating the "with_history" view, the DB complains, because the tables do not match.
// In V1.4 the column will be dropped in base table AND history table.
// This could be probably fixed, by generating history table also with dropped columns
@Column(name = "`select`")
@Index(unique = true)
private String select;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
}
@@ -115,6 +115,14 @@ create table migtest_e_softdelete (
test_string String
) ENGINE = Log();
create table "table" (
"index" String,
"from" String,
"to" String,
"varchar" String,
"foreign" String
) ENGINE = Log();
create table migtest_mtm_c (
id UInt32,
name String
@@ -38,6 +38,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table "table" add column "select" String;
alter table migtest_ckey_detail add column one_key UInt32;
alter table migtest_ckey_detail add column two_key String;
alter table migtest_ckey_parent add column assoc_id UInt32;
@@ -78,3 +79,4 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_status_indextest1
alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
alter table "table" add constraint uq_table_select unique ("select");
@@ -1,5 +1,5 @@
-1091512932, 1.0__initial.sql
308282323, 1.1.sql
863321871, 1.0__initial.sql
1903846331, 1.1.sql
1279151426, 1.2__dropsFor_1.1.sql
1630693278, 1.3.sql
80209848, 1.4__dropsFor_1.3.sql
@@ -140,6 +140,17 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint uq_table_to unique ("to"),
constraint uq_table_varchar unique ("varchar"),
constraint pk_table primary key ("index")
);
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -174,5 +185,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -85,6 +86,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_status_indextest1
alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
alter table "table" add constraint uq_table_select unique ("select");
-- 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 on update restrict;
@@ -1,5 +1,5 @@
150261101, 1.0__initial.sql
-968104039, 1.1.sql
1636200128, 1.0__initial.sql
356413151, 1.1.sql
240919209, 1.2__dropsFor_1.1.sql
-430000356, 1.3.sql
-820814009, 1.4__dropsFor_1.3.sql
@@ -137,6 +137,16 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -162,6 +172,10 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin;
alter table "table" add column sys_period_end timestamp(12) not null generated always as row end;
alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id;
alter table "table" add period system_time (sys_period_start,sys_period_end);
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;
@@ -185,50 +199,21 @@ alter table migtest_e_history6 add period system_time (sys_period_start,sys_peri
-- 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)
);
create table migtest_e_history2_history as (select * from migtest_e_history2) with no data;
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)
);
create table migtest_e_history3_history as (select * from migtest_e_history3) with no data;
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)
);
create table migtest_e_history4_history as (select * from migtest_e_history4) with no data;
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)
);
create table migtest_e_history5_history as (select * from migtest_e_history5) with no data;
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)
);
create table migtest_e_history6_history as (select * from migtest_e_history6) with no data;
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);
create unique index uq_table_to on "table"("to") exclude null keys;
create unique index uq_table_varchar on "table"("varchar") exclude null keys;
create table table_history as (select * from "table") with no data;
alter table "table" add versioning use history table table_history;
-- 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 on update restrict;
@@ -239,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -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,7 +107,6 @@ 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,9 +118,9 @@ 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;
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');
alter table "table" drop versioning;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -171,6 +170,7 @@ 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;
alter table table_history add column "select" varchar(255);
-- apply post alter
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys;
@@ -182,13 +182,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 (
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)
);
create table migtest_e_history_history as (select * from migtest_e_history) with no data;
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';
@@ -197,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is an other comment';
alter table "table" add versioning use history table table_history;
create unique index uq_table_select on "table"("select") exclude null keys;
-- 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 on update restrict;
@@ -219,6 +219,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,8 +1,7 @@
2013908385, 1.0__initial.sql
-1221819499, 1.1.sql
-1073246286, 1.0__initial.sql
2043476851, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-1022780902, 1.3.sql
1155358918, 1.3.sql
-1199420632, 1.4__dropsFor_1.3.sql
-133543359, R__db2_explain_tables.sql
561281075, R__order_views.sql
@@ -137,6 +137,16 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -162,6 +172,10 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin;
alter table "table" add column sys_period_end timestamp(12) not null generated always as row end;
alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id;
alter table "table" add period system_time (sys_period_start,sys_period_end);
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;
@@ -185,50 +199,21 @@ alter table migtest_e_history6 add period system_time (sys_period_start,sys_peri
-- apply post alter
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)
);
create table migtest_e_history2_history as (select * from migtest_e_history2) with no data;
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)
);
create table migtest_e_history3_history as (select * from migtest_e_history3) with no data;
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)
);
create table migtest_e_history4_history as (select * from migtest_e_history4) with no data;
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)
);
create table migtest_e_history5_history as (select * from migtest_e_history5) with no data;
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)
);
create table migtest_e_history6_history as (select * from migtest_e_history6) with no data;
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);
create unique index uq_table_to on "table"("to") exclude null keys;
create unique index uq_table_varchar on "table"("varchar") exclude null keys;
create table table_history as (select * from "table") with no data;
alter table "table" add versioning use history table table_history;
-- 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 on update restrict;
@@ -239,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (o
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -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,7 +107,6 @@ 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,9 +118,9 @@ 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;
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');
alter table "table" drop versioning;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -171,6 +170,7 @@ 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;
alter table table_history add column "select" varchar(255);
-- apply post alter
alter table migtest_e_basic add constraint ck_mgtst__bsc_stts check ( status in ('N','A','I','?'));
create unique index uq_mgtst__b_vs45xo on migtest_e_basic(description) exclude null keys;
@@ -182,13 +182,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 (
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)
);
create table migtest_e_history_history as (select * from migtest_e_history) with no data;
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';
@@ -197,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is an other comment';
alter table "table" add versioning use history table table_history;
create unique index uq_table_select on "table"("select") exclude null keys;
-- 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 on update restrict;
@@ -219,6 +219,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,8 +1,7 @@
-1312137506, 1.0__initial.sql
-1707845451, 1.1.sql
2054922533, 1.0__initial.sql
1256892738, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-1682746660, 1.3.sql
1760988648, 1.3.sql
-1199420632, 1.4__dropsFor_1.3.sql
-133543359, R__db2_explain_tables.sql
561281075, R__order_views.sql
@@ -137,6 +137,16 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -162,6 +172,10 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin;
alter table "table" add column sys_period_end timestamp(12) not null generated always as row end;
alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id;
alter table "table" add period system_time (sys_period_start,sys_period_end);
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;
@@ -185,50 +199,21 @@ alter table migtest_e_history6 add period system_time (sys_period_start,sys_peri
-- 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)
);
create table migtest_e_history2_history as (select * from migtest_e_history2) with no data;
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)
);
create table migtest_e_history3_history as (select * from migtest_e_history3) with no data;
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)
);
create table migtest_e_history4_history as (select * from migtest_e_history4) with no data;
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)
);
create table migtest_e_history5_history as (select * from migtest_e_history5) with no data;
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)
);
create table migtest_e_history6_history as (select * from migtest_e_history6) with no data;
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);
create unique index uq_table_to on "table"("to") exclude null keys;
create unique index uq_table_varchar on "table"("varchar") exclude null keys;
create table table_history as (select * from "table") with no data;
alter table "table" add versioning use history table table_history;
-- 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 on update restrict;
@@ -239,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -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,7 +107,6 @@ 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,9 +118,9 @@ 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;
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');
alter table "table" drop versioning;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -171,6 +170,7 @@ 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;
alter table table_history add column "select" varchar(255);
-- apply post alter
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys;
@@ -182,13 +182,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 (
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)
);
create table migtest_e_history_history as (select * from migtest_e_history) with no data;
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';
@@ -197,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is an other comment';
alter table "table" add versioning use history table table_history;
create unique index uq_table_select on "table"("select") exclude null keys;
-- 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 on update restrict;
@@ -219,6 +219,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,9 +1,7 @@
-1602289007, I__create_tablespaces.sql
1956152763, 1.0__initial.sql
-734701228, 1.1.sql
-1519091511, 1.0__initial.sql
-370964456, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-749133216, 1.3.sql
591329540, 1.3.sql
-1199420632, 1.4__dropsFor_1.3.sql
-133543359, R__db2_explain_tables.sql
561281075, R__order_views.sql
@@ -137,6 +137,16 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -162,6 +172,10 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin;
alter table "table" add column sys_period_end timestamp(12) not null generated always as row end;
alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id;
alter table "table" add period system_time (sys_period_start,sys_period_end);
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;
@@ -185,50 +199,21 @@ alter table migtest_e_history6 add period system_time (sys_period_start,sys_peri
-- 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)
);
create table migtest_e_history2_history as (select * from migtest_e_history2) with no data;
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)
);
create table migtest_e_history3_history as (select * from migtest_e_history3) with no data;
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)
);
create table migtest_e_history4_history as (select * from migtest_e_history4) with no data;
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)
);
create table migtest_e_history5_history as (select * from migtest_e_history5) with no data;
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)
);
create table migtest_e_history6_history as (select * from migtest_e_history6) with no data;
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);
create unique index uq_table_to on "table"("to") exclude null keys;
create unique index uq_table_varchar on "table"("varchar") exclude null keys;
create table table_history as (select * from "table") with no data;
alter table "table" add versioning use history table table_history;
-- 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 on update restrict;
@@ -239,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -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,7 +107,6 @@ 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,9 +118,9 @@ 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;
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');
alter table "table" drop versioning;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -171,6 +170,7 @@ 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;
alter table table_history add column "select" varchar(255);
-- apply post alter
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys;
@@ -182,13 +182,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 (
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)
);
create table migtest_e_history_history as (select * from migtest_e_history) with no data;
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';
@@ -197,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is an other comment';
alter table "table" add versioning use history table table_history;
create unique index uq_table_select on "table"("select") exclude null keys;
-- 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 on update restrict;
@@ -219,6 +219,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor
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;
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,8 +1,7 @@
1956152763, 1.0__initial.sql
-734701228, 1.1.sql
-1519091511, 1.0__initial.sql
-370964456, 1.1.sql
364066694, 1.2__dropsFor_1.1.sql
-749133216, 1.3.sql
591329540, 1.3.sql
-1199420632, 1.4__dropsFor_1.3.sql
-133543359, R__db2_explain_tables.sql
561281075, R__order_views.sql
@@ -140,6 +140,18 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint uq_table_to unique ("to"),
constraint uq_table_varchar unique ("varchar"),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer auto_increment not null,
name varchar(255),
@@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -87,6 +88,8 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
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';
comment on column "table"."index" is 'this is an other comment';
alter table "table" add constraint uq_table_select unique ("select");
-- 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 on update restrict;
@@ -65,6 +65,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique
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 '';
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,6 +1,6 @@
2034298647, 1.0__initial.sql
294462857, 1.1.sql
-1347475412, 1.0__initial.sql
2132717520, 1.1.sql
1279151426, 1.2__dropsFor_1.1.sql
465616489, 1.3.sql
-796269364, 1.3.sql
80209848, 1.4__dropsFor_1.3.sql
@@ -140,6 +140,18 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint uq_table_to unique ("to"),
constraint uq_table_varchar unique ("varchar"),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity not null,
name varchar(255),
@@ -165,6 +177,8 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table "table" add column sys_period_start timestamp default now();
alter table "table" add column sys_period_end timestamp;
alter table migtest_e_history2 add column sys_period_start timestamp default now();
alter table migtest_e_history2 add column sys_period_end timestamp;
alter table migtest_e_history3 add column sys_period_start timestamp default now();
@@ -224,6 +238,18 @@ create table migtest_e_history6_history(
create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history;
create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
create table table_history(
"index" varchar(255),
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
sys_period_start timestamp,
sys_period_end timestamp
);
create view table_with_history as select * from "table" union all select * from table_history;
create trigger table_history_upd before update,delete on "table" for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
-- 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 on update restrict;
@@ -234,5 +260,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -54,7 +54,10 @@ drop view migtest_e_history5_with_history;
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
drop trigger migtest_e_history6_history_upd;
drop view migtest_e_history6_with_history;
drop trigger table_history_upd;
drop view table_with_history;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -92,6 +95,7 @@ alter table migtest_e_history6 alter column test_number2 set null;
alter table migtest_e_history6_history alter column test_number2 set null;
alter table migtest_e_softdelete add column deleted boolean default false not null;
alter table migtest_oto_child add column master_id bigint;
alter table table_history add column "select" varchar(255);
-- apply post alter
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description);
@@ -124,6 +128,10 @@ create view migtest_e_history5_with_history as select * from migtest_e_history5
create trigger migtest_e_history5_history_upd before update,delete on migtest_e_history5 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history;
create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
comment on column "table"."index" is 'this is an other comment';
create view table_with_history as select * from "table" union all select * from table_history;
create trigger table_history_upd before update,delete on "table" for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
alter table "table" add constraint uq_table_select unique ("select");
-- 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 on update restrict;
@@ -86,6 +86,7 @@ create view migtest_e_history4_with_history as select * from migtest_e_history4
create trigger migtest_e_history4_history_upd before update,delete on migtest_e_history4 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history;
create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,7 +1,7 @@
2132375128, 1.0__initial.sql
393141788, 1.1.sql
-1179806373, 1.0__initial.sql
398205555, 1.1.sql
-1366392410, 1.2__dropsFor_1.1.sql
-1336073109, 1.3.sql
-523874424, 1.3.sql
-1382108238, 1.4__dropsFor_1.3.sql
783227075, R__multi_comments.sql
561281075, R__order_views.sql
@@ -140,6 +140,18 @@ create column table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create column table "table" (
"index" nvarchar(255) not null,
"from" nvarchar(255),
"to" nvarchar(255),
"varchar" nvarchar(255),
"foreign" nvarchar(255),
constraint uq_table_to unique ("to"),
constraint uq_table_varchar unique ("varchar"),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create column table migtest_mtm_c (
id integer generated by default as identity not null,
name nvarchar(255),
@@ -229,6 +241,21 @@ alter table migtest_e_history6 add (
);
alter table migtest_e_history6 add period for system_time(sys_period_start,sys_period_end);
alter table migtest_e_history6 add system versioning history table migtest_e_history6_history;
create column table table_history (
"index" nvarchar(255),
"from" nvarchar(255),
"to" nvarchar(255),
"varchar" nvarchar(255),
"foreign" nvarchar(255),
sys_period_start timestamp,
sys_period_end timestamp
);
alter table "table" add (
sys_period_start TIMESTAMP NOT NULL GENERATED ALWAYS AS ROW START,
sys_period_end TIMESTAMP NOT NULL GENERATED ALWAYS AS ROW END
);
alter table "table" add period for system_time(sys_period_start,sys_period_end);
alter table "table" add system versioning history table table_history;
-- foreign keys and indices
-- explicit index "ix_migtest_fk_cascade_one_id" for single column "one_id" of table "migtest_fk_cascade" is not necessary;
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;
@@ -239,5 +266,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
-- explicit index "ix_migtest_e_basic_eref_id" for single column "eref_id" of table "migtest_e_basic" is not necessary;
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;
-- explicit index "ix_table_foreign" for single column ""foreign"" of table ""table"" is not necessary;
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict;
-- explicit index "ix_migtest_e_basic_indextest1" for single column "indextest1" of table "migtest_e_basic" is not necessary;
-- explicit index "ix_migtest_e_basic_indextest5" for single column "indextest5" of table "migtest_e_basic" is not necessary;
-- explicit index "ix_table_from" for single column ""from"" of table ""table"" is not necessary;
@@ -91,7 +91,9 @@ alter table migtest_e_history5 drop system 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 system versioning;
alter table "table" drop system versioning;
-- apply alter tables
alter table "table" add ("select" nvarchar(255));
alter table migtest_ckey_detail add (one_key integer,
two_key nvarchar(127));
alter table migtest_ckey_parent add (assoc_id integer);
@@ -121,6 +123,7 @@ alter table migtest_e_history6 alter (test_number1 integer default 42 not null,
alter table migtest_e_history6_history alter (test_number2 integer);
alter table migtest_e_softdelete add (deleted boolean default false not null);
alter table migtest_oto_child add (master_id bigint);
alter table table_history add ("select" nvarchar(255));
-- apply post alter
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
-- cannot create unique index "uq_migtest_e_basic_description" on table "migtest_e_basic" with nullable columns;
@@ -151,6 +154,9 @@ alter table migtest_e_history3 add system versioning history table migtest_e_his
alter table migtest_e_history4 add system versioning history table migtest_e_history4_history not validated;
alter table migtest_e_history5 add system versioning history table migtest_e_history5_history not validated;
alter table migtest_e_history6 add system versioning history table migtest_e_history6_history not validated;
comment on column "table"."index" is 'this is an other comment';
alter table "table" add system versioning history table table_history not validated;
-- cannot create unique index "uq_table_select" on table ""table"" with nullable columns;
-- foreign keys and indices
-- explicit index "ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c" for single column "migtest_mtm_c_id" of table "migtest_mtm_c_migtest_mtm_m" is not necessary;
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;
@@ -132,6 +132,7 @@ alter table migtest_e_history2 add system versioning history table migtest_e_his
alter table migtest_e_history3 add system versioning history table migtest_e_history3_history not validated;
alter table migtest_e_history4 add system versioning history table migtest_e_history4_history not validated;
alter table migtest_e_history6 add system versioning history table migtest_e_history6_history not validated;
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,8 +1,8 @@
-745347271, I__create_procs.sql
-1191817607, 1.0__initial.sql
975653326, 1.1.sql
1934891896, 1.0__initial.sql
187688059, 1.1.sql
197547825, 1.2__dropsFor_1.1.sql
-98538062, 1.3.sql
-1989736027, 1.3.sql
1812245353, 1.4__dropsFor_1.3.sql
1906063401, R__order_views_hana.sql
@@ -140,6 +140,18 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table "table" (
"index" varchar(255) not null,
"from" varchar(255),
"to" varchar(255),
"varchar" varchar(255),
"foreign" varchar(255),
constraint uq_table_to unique ("to"),
constraint uq_table_varchar unique ("varchar"),
constraint pk_table primary key ("index")
);
comment on column "table"."index" is 'this is a comment';
create table migtest_mtm_c (
id integer generated by default as identity (start with 1) not null,
name varchar(255),
@@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on "table" ("foreign");
alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") 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);
create index ix_table_from on "table" ("from");
@@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table "table" add column "select" varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -87,6 +88,8 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
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';
comment on column "table"."index" is 'this is an other comment';
alter table "table" add constraint uq_table_select unique ("select");
-- 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 on update restrict;
@@ -65,6 +65,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique
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 '';
comment on column "table"."index" is 'this is a comment';
-- 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 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;
@@ -1,7 +1,7 @@
614593077, 1.0__initial.sql
-788233032, 1.1.sql
-917796012, 1.0__initial.sql
-838725141, 1.1.sql
-300925212, 1.2__dropsFor_1.1.sql
121126259, 1.3.sql
-1549893170, 1.3.sql
-972999284, 1.4__dropsFor_1.3.sql
861001272, R__order_views_hsqldb.sql
@@ -137,6 +137,17 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table `table` (
`index` varchar(255) not null comment 'this is a comment',
`from` varchar(255),
`to` varchar(255),
`varchar` varchar(255),
`foreign` varchar(255),
constraint uq_table_to unique (`to`),
constraint uq_table_varchar unique (`varchar`),
constraint pk_table primary key (`index`)
);
create table migtest_mtm_c (
id integer auto_increment not null,
name varchar(255),
@@ -162,6 +173,7 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table `table` add system versioning;
alter table migtest_e_history2 add system versioning;
alter table migtest_e_history3 add system versioning;
alter table migtest_e_history4 add system versioning;
@@ -177,5 +189,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on `table` (`foreign`);
alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) 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);
create index ix_table_from on `table` (`from`);
@@ -43,6 +43,7 @@ SET @@system_versioning_alter_history = 1;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table `table` add column `select` varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -77,6 +78,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
alter table migtest_e_history comment = 'We have history now';
alter table `table` add constraint uq_table_select unique (`select`);
-- 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 on update restrict;
@@ -1,5 +1,5 @@
1992643861, 1.0__initial.sql
-1677772226, 1.1.sql
675320779, 1.0__initial.sql
840323734, 1.1.sql
-828985759, 1.2__dropsFor_1.1.sql
-1470028617, 1.3.sql
-446860935, 1.4__dropsFor_1.3.sql
@@ -137,6 +137,17 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table `table` (
`index` varchar(255) not null comment 'this is a comment',
`from` varchar(255),
`to` varchar(255),
`varchar` varchar(255),
`foreign` varchar(255),
constraint uq_table_to unique (`to`),
constraint uq_table_varchar unique (`varchar`),
constraint pk_table primary key (`index`)
);
create table migtest_mtm_c (
id integer auto_increment not null,
name varchar(255),
@@ -162,6 +173,7 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table `table` add system versioning;
alter table migtest_e_history2 add system versioning;
alter table migtest_e_history3 add system versioning;
alter table migtest_e_history4 add system versioning;
@@ -177,5 +189,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on `table` (`foreign`);
alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) 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);
create index ix_table_from on `table` (`from`);
@@ -43,6 +43,7 @@ SET @@system_versioning_alter_history = 1;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
-- apply alter tables
alter table `table` add column `select` varchar(255);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_parent add column assoc_id integer;
@@ -77,6 +78,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
alter table migtest_e_history comment = 'We have history now';
alter table `table` add constraint uq_table_select unique (`select`);
-- 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 on update restrict;
@@ -1,6 +1,6 @@
1835064798, I__create_procs.sql
1992643861, 1.0__initial.sql
-1677772226, 1.1.sql
675320779, 1.0__initial.sql
840323734, 1.1.sql
2123392915, 1.2__dropsFor_1.1.sql
-1470028617, 1.3.sql
-692020559, 1.4__dropsFor_1.3.sql
@@ -100,6 +100,15 @@
<column name="id" type="integer" primaryKey="true"/>
<column name="test_string" type="varchar"/>
</createTable>
<createTable name="&quot;table&quot;" withHistory="true" identityType="external" pkName="pk_table">
<column name="&quot;index&quot;" type="varchar" primaryKey="true" comment="this is a comment"/>
<column name="&quot;from&quot;" type="varchar"/>
<column name="&quot;to&quot;" type="varchar"/>
<column name="&quot;varchar&quot;" type="varchar"/>
<column name="&quot;foreign&quot;" type="varchar" references="&quot;table&quot;.&quot;index&quot;" foreignKeyName="fk_table_foreign" foreignKeyIndex="ix_table_foreign"/>
<uniqueConstraint name="uq_table_to" columnNames="&quot;to&quot;" oneToOne="false" nullableColumns="&quot;to&quot;"/>
<uniqueConstraint name="uq_table_varchar" columnNames="&quot;varchar&quot;" oneToOne="false" nullableColumns="&quot;varchar&quot;"/>
</createTable>
<createTable name="migtest_mtm_c" pkName="pk_migtest_mtm_c">
<column name="id" type="integer" primaryKey="true"/>
<column name="name" type="varchar"/>
@@ -118,6 +127,7 @@
</createTable>
<createIndex indexName="ix_migtest_e_basic_indextest1" tableName="migtest_e_basic" columns="indextest1"/>
<createIndex indexName="ix_migtest_e_basic_indextest5" tableName="migtest_e_basic" columns="indextest5"/>
<createIndex indexName="ix_table_from" tableName="&quot;table&quot;" columns="&quot;from&quot;"/>
<createIndex indexName="idxd_migtest_0" tableName="migtest_oto_child" columns="" definition="create index idxd_migtest_0 on migtest_oto_child using hash (upper(name)) where upper(name) = 'JIM'" platforms="POSTGRES"/>
<createIndex indexName="ix_migtest_oto_child_lowername_id" tableName="migtest_oto_child" columns="lower(name),id" concurrent="true" platforms="POSTGRES"/>
<createIndex indexName="ix_migtest_oto_child_lowername" tableName="migtest_oto_child" columns="lower(name)" platforms="POSTGRES"/>
@@ -72,6 +72,11 @@
<addColumn tableName="migtest_e_softdelete">
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
</addColumn>
<alterColumn columnName="&quot;index&quot;" tableName="&quot;table&quot;" withHistory="true" comment="this is an other comment"/>
<addColumn tableName="&quot;table&quot;" withHistory="true">
<column name="&quot;select&quot;" type="varchar"/>
</addColumn>
<addUniqueConstraint constraintName="uq_table_select" tableName="&quot;table&quot;" columnNames="&quot;select&quot;" oneToOne="false" nullableColumns="&quot;select&quot;"/>
<createTable name="migtest_e_user" pkName="pk_migtest_e_user">
<column name="id" type="integer" primaryKey="true"/>
</createTable>
@@ -40,8 +40,7 @@
<column name="name" type="varchar(127)" notnull="true"/>
<uniqueConstraint name="uq_migtest_e_ref_name" columnNames="name" oneToOne="false" nullableColumns=""/>
</createTable>
<alterTable name="migtest_mtm_c" tablespace="$TABLESPACE_DEFAULT" indexTablespace="$TABLESPACE_DEFAULT" lobTablespace="$TABLESPACE_DEFAULT"/>
<alterTable name="migtest_mtm_m" tablespace="$TABLESPACE_DEFAULT" indexTablespace="$TABLESPACE_DEFAULT" lobTablespace="$TABLESPACE_DEFAULT"/>
<alterColumn columnName="&quot;index&quot;" tableName="&quot;table&quot;" withHistory="true" comment="this is a comment"/>
<addUniqueConstraint constraintName="uq_m12_otoc72" tableName="migtest_oto_child" columnNames="name" oneToOne="false" nullableColumns="name" platforms="MYSQL"/>
<addUniqueConstraint constraintName="uq_migtest_oto_master_name" tableName="migtest_oto_master" columnNames="name" oneToOne="false" nullableColumns="name" platforms="MYSQL"/>
<createIndex indexName="ix_migtest_e_basic_indextest1" tableName="migtest_e_basic" columns="indextest1"/>
@@ -137,6 +137,17 @@ create table migtest_e_softdelete (
constraint pk_migtest_e_softdelete primary key (id)
);
create table `table` (
`index` varchar(255) not null comment 'this is a comment',
`from` varchar(255),
`to` varchar(255),
`varchar` varchar(255),
`foreign` varchar(255),
constraint uq_table_to unique (`to`),
constraint uq_table_varchar unique (`varchar`),
constraint pk_table primary key (`index`)
);
create table migtest_mtm_c (
id integer auto_increment not null,
name varchar(255),
@@ -162,6 +173,8 @@ create table migtest_oto_master (
);
-- apply alter tables
alter table `table` add column sys_period_start datetime(6) default now(6);
alter table `table` add column sys_period_end datetime(6);
alter table migtest_e_history2 add column sys_period_start datetime(6) default now(6);
alter table migtest_e_history2 add column sys_period_end datetime(6);
alter table migtest_e_history3 add column sys_period_start datetime(6) default now(6);
@@ -271,6 +284,28 @@ create trigger migtest_e_history6_history_del before delete on migtest_e_history
end$$
unlock tables;
create table table_history(
`index` varchar(255),
`from` varchar(255),
`to` varchar(255),
`varchar` varchar(255),
`foreign` varchar(255),
sys_period_start datetime(6),
sys_period_end datetime(6)
);
create view table_with_history as select * from `table` union all select * from table_history;
lock tables "table" write;
delimiter $$
create trigger table_history_upd before update on "table" for each row begin
insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign");
set NEW.sys_period_start = now(6);
end$$
delimiter $$
create trigger table_history_del before delete on "table" for each row begin
insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign");
end$$
unlock tables;
-- 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 on update restrict;
@@ -281,5 +316,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for
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 on update restrict;
create index ix_table_foreign on `table` (`foreign`);
alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) 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);
create index ix_table_from on `table` (`from`);

Some files were not shown because too many files have changed in this diff Show More