DbMigration supports altering UniqueConstraints and foreign keys (#1279)

* NEW: Ebean reads version from pop.properties and prints it at start up

* DDL generation and migration can append a header and platformMigration is prepared to append epilog & prolog to scripts

* FIX: Set identity only, if it is not the platform default type

* Updated reference scripts

* ADD basic support for foreign key migration

* DbMigration detects alter foreign keys

* tests
This commit is contained in:
Roland Praml
2018-02-26 14:24:52 +13:00
committed by Rob Bygrave
parent a64a244745
commit da7bb834e7
70 changed files with 1806 additions and 80 deletions
@@ -6,7 +6,9 @@ import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
import io.ebeaninternal.dbmigration.migration.CreateTable;
@@ -59,6 +61,10 @@ public class BaseDdlHandler implements DdlHandler {
generate(writer, (AddHistoryTable) change);
} else if (change instanceof DropHistoryTable) {
generate(writer, (DropHistoryTable) change);
} else if (change instanceof AddUniqueConstraint) {
generate(writer, (AddUniqueConstraint) change);
} else if (change instanceof AlterForeignKey) {
generate(writer, (AlterForeignKey) change);
} else {
throw new IllegalArgumentException("Unsupported change: " + change);
}
@@ -125,4 +131,13 @@ public class BaseDdlHandler implements DdlHandler {
tableDdl.generate(writer, dropIndex);
}
@Override
public void generate(DdlWrite writer, AddUniqueConstraint constraint) throws IOException {
tableDdl.generate(writer, constraint);
}
@Override
public void generate(DdlWrite writer, AlterForeignKey alterForeignKey) throws IOException {
tableDdl.generate(writer, alterForeignKey);
}
}
@@ -3,7 +3,9 @@ package io.ebeaninternal.dbmigration.ddlgeneration;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
import io.ebeaninternal.dbmigration.migration.CreateTable;
@@ -41,6 +43,10 @@ public interface DdlHandler {
void generate(DdlWrite writer, DropIndex dropIndex) throws IOException;
void generate(DdlWrite writer, AddUniqueConstraint constraint) throws IOException;
void generate(DdlWrite writer, AlterForeignKey alterForeignKey) throws IOException;
void generateProlog(DdlWrite write) throws IOException;
void generateEpilog(DdlWrite write) throws IOException;
@@ -3,7 +3,9 @@ package io.ebeaninternal.dbmigration.ddlgeneration;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
import io.ebeaninternal.dbmigration.migration.CreateTable;
import io.ebeaninternal.dbmigration.migration.DropColumn;
@@ -69,6 +71,16 @@ public interface TableDdl {
void generate(DdlWrite writer, DropIndex dropIndex) throws IOException;
/**
* Write add unique constraint.
*/
void generate(DdlWrite writer, AddUniqueConstraint constraint) throws IOException;
/**
* Writes alter foreign key statements.
* @throws IOException
*/
void generate(DdlWrite writer, AlterForeignKey alterForeignKey) throws IOException;
/**
* Generate any extra DDL such as stored procedures or TableValueParameters.
*/
@@ -13,7 +13,9 @@ import io.ebeaninternal.dbmigration.ddlgeneration.platform.util.IndexSet;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.Column;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
import io.ebeaninternal.dbmigration.migration.CreateTable;
@@ -330,7 +332,7 @@ public class BaseTableDdl implements TableDdl {
}
String[] columnNames = {col.getName()};
write.apply()
.append(platformDdl.alterTableAddUniqueConstraint(tableName, uqName, columnNames, Boolean.TRUE.equals(col.isNotnull())))
.append(platformDdl.alterTableAddUniqueConstraint(tableName, uqName, columnNames, Boolean.TRUE.equals(col.isNotnull()) ? null : columnNames))
.endOfStatement();
write.dropAllForeignKeys()
@@ -340,9 +342,10 @@ public class BaseTableDdl implements TableDdl {
for (UniqueConstraint constraint : externalCompoundUnique) {
String uqName = constraint.getName();
String[] columnNames = StringHelper.delimitedToArray(constraint.getColumnNames(), ",", false);
String[] columnNames = SplitColumns.split(constraint.getColumnNames());
String[] nullableColumns = SplitColumns.split(constraint.getNullableColumns());
write.apply()
.append(platformDdl.alterTableAddUniqueConstraint(tableName, uqName, columnNames, false)) // TODO: check if nullable
.append(platformDdl.alterTableAddUniqueConstraint(tableName, uqName, columnNames, nullableColumns))
.endOfStatement();
write.dropAllForeignKeys()
@@ -639,6 +642,40 @@ public class BaseTableDdl implements TableDdl {
.append(platformDdl.dropIndex(dropIndex.getIndexName(), dropIndex.getTableName()))
.endOfStatement();
}
@Override
public void generate(DdlWrite writer, AddUniqueConstraint constraint) throws IOException {
if (DdlHelp.isDropConstraint(constraint.getColumnNames())) {
String ddl = platformDdl.alterTableDropUniqueConstraint(constraint.getTableName(), constraint.getConstraintName());
if (hasValue(ddl)) {
writer.apply().append(ddl).endOfStatement();
}
} else {
String[] cols = SplitColumns.split(constraint.getColumnNames());
String[] nullableColumns = SplitColumns.split(constraint.getNullableColumns());
String ddl = platformDdl.alterTableAddUniqueConstraint(constraint.getTableName(), constraint.getConstraintName(), cols, nullableColumns);
if (hasValue(ddl)) {
writer.apply().append(ddl).endOfStatement();
}
}
}
@Override
public void generate(DdlWrite writer, AlterForeignKey alterForeignKey) throws IOException {
if (DdlHelp.isDropForeignKey(alterForeignKey.getColumnNames())) {
String ddl = platformDdl.alterTableDropForeignKey(alterForeignKey.getTableName(),
alterForeignKey.getName());
if (hasValue(ddl)) {
writer.apply().append(ddl).endOfStatement();
}
} else {
String ddl = platformDdl.alterTableAddForeignKey(new WriteForeignKey(alterForeignKey));
if (hasValue(ddl)) {
writer.apply().append(ddl).endOfStatement();
}
}
}
/**
* Add add history table DDL.
@@ -932,7 +969,7 @@ public class BaseTableDdl implements TableDdl {
String[] cols = {alter.getColumnName()};
boolean notNull = alter.isNotnull() != null ? alter.isNotnull() : Boolean.TRUE.equals(alter.isNotnull());
writer.apply()
.append(platformDdl.alterTableAddUniqueConstraint(alter.getTableName(), uqName, cols, notNull))
.append(platformDdl.alterTableAddUniqueConstraint(alter.getTableName(), uqName, cols, notNull ? null : cols))
.endOfStatement();
writer.dropAllForeignKeys()
@@ -18,12 +18,12 @@ public class DB2Ddl extends PlatformDdl {
}
@Override
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, boolean notNull) {
if (notNull) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, true);
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
if (nullableColumns == null || nullableColumns.length == 0) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
} else {
// Hmm: Complex workaround: https://www.ibm.com/developerworks/mydeveloperworks/blogs/SQLTips4DB2LUW/entry/unique_where_not_null_indexes26?lang=en
return "-- NOT SUPPORTED " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, true);
return "-- NOT SUPPORTED " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
}
}
@@ -5,18 +5,35 @@ public class DdlHelp {
public static final String DROP_COMMENT = "DROP COMMENT";
/**
* Return true if the default value is the special DROP DEFAULT value.
*/
public static boolean isDropDefault(String defaultValue) {
return DROP_DEFAULT.equals(defaultValue);
}
public static final String DROP_CONSTRAINT = "DROP CONSTRAINT";
public static final String DROP_FOREIGN_KEY = "DROP FOREIGN KEY";
/**
* Return true if the default value is the special DROP DEFAULT value.
*/
public static boolean isDropComment(String comment) {
return DROP_COMMENT.equals(comment);
public static boolean isDropDefault(String value) {
return DROP_DEFAULT.equals(value);
}
/**
* Return true if the default value is the special DROP COMMENT value.
*/
public static boolean isDropComment(String value) {
return DROP_COMMENT.equals(value);
}
/**
* Return true if the default value is the special DROP CONSTRAINT value.
*/
public static boolean isDropConstraint(String value) {
return DROP_CONSTRAINT.equals(value);
}
/**
* Return true if the default value is the special DROP FOREIGN KEY value.
*/
public static boolean isDropForeignKey(String value) {
return DROP_FOREIGN_KEY.equals(value);
}
}
@@ -108,6 +108,15 @@ public class MySqlDdl extends PlatformDdl {
*/
@Override
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException {
if (DdlHelp.isDropComment(tableComment)) {
tableComment = "";
}
apply.append(String.format("alter table %s comment = '%s'", tableName, tableComment)).endOfStatement();
}
@Override
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) throws IOException {
// alter comment currently not supported as it requires to repeat whole column definition
}
}
@@ -22,6 +22,16 @@ public class Oracle10Ddl extends PlatformDdl {
this.identitySuffix = " generated always as identity";
}
@Override
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
if (nullableColumns == null || nullableColumns.length == 0) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
} else {
// Hmm: https://stackoverflow.com/questions/11893134/oracle-create-unique-index-but-ignore-nulls
return "-- NOT YET IMPLEMENTED: " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
}
}
@Override
protected void appendForeignKeyOnUpdate(StringBuilder buffer, ConstraintMode mode) {
// do nothing, no on update clause for oracle
@@ -432,7 +432,7 @@ public class PlatformDdl {
* <p>
* Overridden by MsSqlServer for specific null handling on unique constraints.
*/
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, boolean notNull) {
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(uqName).append(" unique ");
@@ -63,9 +63,9 @@ public class SqlServerDdl extends PlatformDdl {
* MsSqlServer specific null handling on unique constraints.
*/
@Override
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, boolean notNull) {
if (notNull) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, notNull);
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
if (nullableColumns == null || nullableColumns.length == 0) {
return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
}
if (uqName == null) {
throw new NullPointerException();
@@ -82,7 +82,7 @@ public class SqlServerDdl extends PlatformDdl {
}
sb.append(") where");
String sep = " ";
for (String column : columns) {
for (String column : nullableColumns) {
sb.append(sep).append(column).append(" is not null");
sep = " and ";
}
@@ -2,6 +2,7 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.annotation.ConstraintMode;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.Column;
import io.ebeaninternal.dbmigration.migration.ForeignKey;
@@ -37,6 +38,17 @@ class WriteForeignKey {
this.onUpdate = modeOf(key.getOnUpdate());
}
WriteForeignKey(AlterForeignKey key) {
this.tableName = key.getTableName();
this.indexName = key.getIndexName();
this.fkName = key.getName();
this.cols = toCols(key.getColumnNames());
this.refTableName = key.getRefTableName();
this.refCols = toCols(key.getRefColumnNames());
this.onDelete = modeOf(key.getOnDelete());
this.onUpdate = modeOf(key.getOnUpdate());
}
WriteForeignKey(String tableName, Column column) {
this.tableName = tableName;
this.indexName = column.getForeignKeyIndex();
@@ -0,0 +1,137 @@
package io.ebeaninternal.dbmigration.migration;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* TODO
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "addUniqueConstraint")
public class AddUniqueConstraint {
@XmlAttribute(name = "constraintName", required = true)
protected String constraintName;
@XmlAttribute(name = "tableName", required = true)
protected String tableName;
@XmlAttribute(name = "columnNames", required = true)
protected String columnNames;
@XmlAttribute(name = "nullableColumns", required = true)
protected String nullableColumns;
@XmlAttribute(name = "oneToOne", required = false)
protected Boolean oneToOne;
/**
* Gets the value of the constraintName property.
*
* @return possible object is
* {@link String }
*/
public String getConstraintName() {
return constraintName;
}
/**
* Sets the value of the constraintName property.
*
* @param value allowed object is
* {@link String }
*/
public void setConstraintName(String value) {
this.constraintName = value;
}
/**
* Gets the value of the tableName property.
*
* @return possible object is
* {@link String }
*/
public String getTableName() {
return tableName;
}
/**
* Sets the value of the tableName property.
*
* @param value allowed object is
* {@link String }
*/
public void setTableName(String tableName) {
this.tableName = tableName;
}
/**
* Gets the value of the columnNames property.
*
* @return possible object is
* {@link String }
*/
public String getColumnNames() {
return columnNames;
}
/**
* Sets the value of the columnNames property.
*
* @param value allowed object is
* {@link String }
*/
public void setColumnNames(String value) {
this.columnNames = value;
}
/**
* Gets the value of the nullableColumns property.
*
* @return possible object is
* {@link String }
*/
public String getNullableColumns() {
return nullableColumns;
}
/**
* Sets the value of the nullableColumns property.
*
* @param value allowed object is
* {@link String }
*/
public void setNullableColumns(String value) {
this.nullableColumns = value;
}
/**
* Gets the value of the oneToOne property.
*
* @return true if oneToOne was set
*/
public boolean isOneToOne() {
return Boolean.TRUE.equals(oneToOne);
}
/**
* Sets the value of the oneToOne property.
*
* @param value boolean
*/
public void setOneToOne(boolean oneToOne) {
this.oneToOne = oneToOne;
}
}
@@ -0,0 +1,199 @@
package io.ebeaninternal.dbmigration.migration;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* TODO
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "foreignKey")
public class AlterForeignKey {
@XmlAttribute(name = "name", required = true)
protected String name;
@XmlAttribute(name = "columnNames", required = true)
protected String columnNames;
@XmlAttribute(name = "refColumnNames", required = true)
protected String refColumnNames;
@XmlAttribute(name = "refTableName", required = true)
protected String refTableName;
@XmlAttribute(name = "indexName")
protected String indexName;
@XmlAttribute(name = "tableName", required = true)
protected String tableName;
@XmlAttribute(name = "onDelete")
protected String onDelete;
@XmlAttribute(name = "onUpdate")
protected String onUpdate;
/**
* Gets the value of the name property.
*
* @return possible object is
* {@link String }
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value allowed object is
* {@link String }
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the columnNames property.
*
* @return possible object is
* {@link String }
*/
public String getColumnNames() {
return columnNames;
}
/**
* Sets the value of the columnNames property.
*
* @param value allowed object is
* {@link String }
*/
public void setColumnNames(String value) {
this.columnNames = value;
}
/**
* Gets the value of the refColumnNames property.
*
* @return possible object is
* {@link String }
*/
public String getRefColumnNames() {
return refColumnNames;
}
/**
* Sets the value of the refColumnNames property.
*
* @param value allowed object is
* {@link String }
*/
public void setRefColumnNames(String value) {
this.refColumnNames = value;
}
/**
* Gets the value of the refTableName property.
*
* @return possible object is
* {@link String }
*/
public String getRefTableName() {
return refTableName;
}
/**
* Sets the value of the refTableName property.
*
* @param value allowed object is
* {@link String }
*/
public void setRefTableName(String value) {
this.refTableName = value;
}
/**
* Gets the value of the indexName property.
*
* @return possible object is
* {@link String }
*/
public String getIndexName() {
return indexName;
}
/**
* Sets the value of the indexName property.
*
* @param value allowed object is
* {@link String }
*/
public void setIndexName(String value) {
this.indexName = value;
}
/**
* Gets the value of the tableName property.
*
* @return possible object is
* {@link String }
*/
public String getTableName() {
return tableName;
}
/**
* Sets the value of the tableName property.
*
* @param value allowed object is
* {@link String }
*/
public void setTableName(String value) {
this.tableName = value;
}
/**
* Gets the value of the onDelete property.
*
* @return possible object is
* {@link String }
*/
public String getOnDelete() {
return onDelete;
}
/**
* Sets the value of the onDelete property.
*
* @param value allowed object is
* {@link String }
*/
public void setOnDelete(String value) {
this.onDelete = value;
}
/**
* Gets the value of the onUpdate property.
*
* @return possible object is
* {@link String }
*/
public String getOnUpdate() {
return onUpdate;
}
/**
* Sets the value of the onUpdate property.
*
* @param value allowed object is
* {@link String }
*/
public void setOnUpdate(String value) {
this.onUpdate = value;
}
}
@@ -57,7 +57,9 @@ public class ChangeSet {
@XmlElement(name = "alterColumn", type = AlterColumn.class),
@XmlElement(name = "renameColumn", type = RenameColumn.class),
@XmlElement(name = "createIndex", type = CreateIndex.class),
@XmlElement(name = "dropIndex", type = DropIndex.class)
@XmlElement(name = "dropIndex", type = DropIndex.class),
@XmlElement(name = "addUniqueConstraint", type = AddUniqueConstraint.class),
@XmlElement(name = "alterForeignKey", type = AlterForeignKey.class),
})
protected List<Object> changeSetChildren;
@XmlAttribute(name = "type", required = true)
@@ -194,5 +194,17 @@ public class ObjectFactory {
return new DdlScript();
}
/**
* Create an instance of {@link CompoundUniqueConstraint }
*/
public AddUniqueConstraint createCompoundUniqueConstraint() {
return new AddUniqueConstraint();
}
/**
* Create an instance of {@link AddUniqueConstraint }
*/
public AlterForeignKey createAlterForeignKey() {
return new AlterForeignKey();
}
}
@@ -30,9 +30,16 @@ public class UniqueConstraint {
@XmlAttribute(name = "name", required = true)
protected String name;
@XmlAttribute(name = "columnNames", required = true)
protected String columnNames;
@XmlAttribute(name = "oneToOne", required = false)
protected Boolean oneToOne;
@XmlAttribute(name = "nullableColumns", required = true)
protected String nullableColumns;
/**
* Gets the value of the name property.
*
@@ -72,5 +79,43 @@ public class UniqueConstraint {
public void setColumnNames(String value) {
this.columnNames = value;
}
/**
* Gets the value of the oneToOne property.
*
* @return true if oneToOne was set
*/
public boolean isOneToOne() {
return Boolean.TRUE.equals(oneToOne);
}
/**
* Sets the value of the oneToOne property.
*
* @param value boolean
*/
public void setOneToOne(boolean oneToOne) {
this.oneToOne = oneToOne;
}
/**
* Gets the value of the nullableColumns property.
*
* @return possible object is
* {@link String }
*/
public String getNullableColumns() {
return nullableColumns;
}
/**
* Sets the value of the nullableColumns property.
*
* @param value allowed object is
* {@link String }
*/
public void setNullableColumns(String value) {
this.nullableColumns = value;
}
}
@@ -404,7 +404,9 @@ public class MColumn {
alter.setCheckConstraint(newColumn.checkConstraint);
}
}
if (different(references, newColumn.references)) {
if (different(references, newColumn.references)
|| hasValue(newColumn.references) && fkeyOnDelete != newColumn.fkeyOnDelete
|| hasValue(newColumn.references) && fkeyOnUpdate != newColumn.fkeyOnUpdate) {
// foreign key change
AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
if (hasValue(foreignKeyName)) {
@@ -418,6 +420,12 @@ public class MColumn {
alter.setReferences(newColumn.references);
alter.setForeignKeyName(newColumn.foreignKeyName);
alter.setForeignKeyIndex(newColumn.foreignKeyIndex);
if (newColumn.fkeyOnDelete != null) {
alter.setForeignKeyOnDelete(fkeyModeOf(newColumn.fkeyOnDelete));
}
if (newColumn.fkeyOnUpdate != null) {
alter.setForeignKeyOnUpdate(fkeyModeOf(newColumn.fkeyOnUpdate));
}
}
}
@@ -513,6 +521,11 @@ public class MColumn {
comment = null;
}
}
if (hasValue(alterColumn.getForeignKeyOnDelete())) {
fkeyOnDelete = fkeyMode(alterColumn.getForeignKeyOnDelete());
}
if (hasValue(alterColumn.getForeignKeyOnUpdate())) {
fkeyOnUpdate = fkeyMode(alterColumn.getForeignKeyOnUpdate());
}
}
}
@@ -1,9 +1,12 @@
package io.ebeaninternal.dbmigration.model;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.ForeignKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* A unique constraint for multiple columns.
@@ -46,6 +49,32 @@ public class MCompoundForeignKey {
fk.setRefTableName(referenceTable);
return fk;
}
/**
* Create and return an AlterForeignKey migration element.
*/
public AlterForeignKey addForeignKey(String tableName) {
AlterForeignKey fk = new AlterForeignKey();
fk.setName(name);
fk.setIndexName(indexName);
fk.setColumnNames(toColumnNames(columns));
fk.setRefColumnNames(toColumnNames(referenceColumns));
fk.setRefTableName(referenceTable);
fk.setTableName(tableName);
return fk;
}
/**
* Create and return an AlterForeignKey migration element.
*/
public AlterForeignKey dropForeignKey(String tableName) {
AlterForeignKey fk = new AlterForeignKey();
fk.setName(name);
fk.setIndexName(indexName);
fk.setColumnNames(DdlHelp.DROP_FOREIGN_KEY);
fk.setTableName(tableName);
return fk;
}
/**
* Add a counter to the foreign key and index names to avoid duplication.
@@ -99,4 +128,24 @@ public class MCompoundForeignKey {
return sb.toString();
}
@Override
public int hashCode() {
return Objects.hash(columns, indexName, name, referenceColumns, referenceTable);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof MCompoundForeignKey))
return false;
MCompoundForeignKey other = (MCompoundForeignKey) obj;
return Objects.equals(columns, other.columns)
&& Objects.equals(indexName, other.indexName)
&& Objects.equals(name, other.name)
&& Objects.equals(referenceColumns, other.referenceColumns)
&& Objects.equals(referenceTable, other.referenceTable);
}
}
@@ -1,5 +1,11 @@
package io.ebeaninternal.dbmigration.model;
import java.util.Arrays;
import java.util.Objects;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.UniqueConstraint;
/**
* A unique constraint for multiple columns.
* <p>
@@ -20,6 +26,8 @@ public class MCompoundUniqueConstraint {
* The columns combined to be unique.
*/
private final String[] columns;
private String[] nullableColumns;
public MCompoundUniqueConstraint(String[] columns, boolean oneToOne, String name) {
this.name = name;
@@ -47,4 +55,78 @@ public class MCompoundUniqueConstraint {
public String getName() {
return name;
}
public UniqueConstraint getUniqueConstraint() {
UniqueConstraint uq = new UniqueConstraint();
uq.setName(getName());
uq.setColumnNames(join(columns));
uq.setNullableColumns(join(nullableColumns));
uq.setOneToOne(isOneToOne());
return uq;
}
/**
* Return a AddUniqueConstraint migration for this constraint.
*/
public AddUniqueConstraint addUniqueConstraint(String tableName) {
AddUniqueConstraint create = new AddUniqueConstraint();
create.setConstraintName(getName());
create.setTableName(tableName);
create.setColumnNames(join(columns));
create.setNullableColumns(join(nullableColumns));
create.setOneToOne(isOneToOne());
return create;
}
/**
* Create a AddUniqueConstraint migration with 'DROP CONSTRAINT' set for this index.
*/
public AddUniqueConstraint dropUniqueConstraint(String tableName) {
AddUniqueConstraint dropUniqueConstraint = new AddUniqueConstraint();
dropUniqueConstraint.setConstraintName(name);
dropUniqueConstraint.setTableName(tableName);
dropUniqueConstraint.setColumnNames(DdlHelp.DROP_CONSTRAINT);
dropUniqueConstraint.setNullableColumns(join(nullableColumns));
return dropUniqueConstraint;
}
public void setNullableColumns(String[] nullableColumns) {
if (nullableColumns != null && nullableColumns.length == 0) {
this.nullableColumns = null;
} else {
this.nullableColumns = nullableColumns;
}
}
private String join(String[] arr) {
if (arr == null) {
return "";
}
StringBuilder sb = new StringBuilder(50);
for (int i = 0; i < arr.length; i++) {
if (i > 0) {
sb.append(",");
}
sb.append(arr[i]);
}
return sb.toString();
}
@Override
public int hashCode() {
return Arrays.hashCode(columns) + 31 * Objects.hash(name, oneToOne);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof MCompoundUniqueConstraint)) {
return false;
}
MCompoundUniqueConstraint other = (MCompoundUniqueConstraint) obj;
return Arrays.equals(columns, other.columns)
&& Arrays.equals(nullableColumns, other.nullableColumns)
&& Objects.equals(name, other.name)
&& oneToOne == other.oneToOne;
}
}
@@ -1,6 +1,7 @@
package io.ebeaninternal.dbmigration.model;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
@@ -10,6 +11,7 @@ import io.ebeaninternal.dbmigration.migration.CreateTable;
import io.ebeaninternal.dbmigration.migration.DropColumn;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropTable;
import io.ebeaninternal.dbmigration.migration.ForeignKey;
import io.ebeaninternal.dbmigration.migration.IdentityType;
import io.ebeaninternal.dbmigration.migration.UniqueConstraint;
import org.slf4j.Logger;
@@ -165,9 +167,36 @@ public class MTable {
for (Column column : cols) {
addColumn(column);
}
List<UniqueConstraint> uqConstraints = createTable.getUniqueConstraint();
for (UniqueConstraint uq : uqConstraints) {
MCompoundUniqueConstraint mUq = new MCompoundUniqueConstraint(
SplitColumns.split(uq.getColumnNames()), uq.isOneToOne(), uq.getName());
mUq.setNullableColumns(SplitColumns.split(uq.getNullableColumns()));
uniqueConstraints.add(mUq);
}
for (ForeignKey fk : createTable.getForeignKey()) {
if (DdlHelp.isDropForeignKey(fk.getColumnNames())) {
removeForeignKey(fk.getName());
} else {
addForeignKey(fk.getName(), fk.getRefTableName(), fk.getIndexName(), fk.getColumnNames(), fk.getRefColumnNames());
}
}
}
public void addForeignKey(String name, String refTableName, String indexName, String columnNames,
String refColumnNames) {
MCompoundForeignKey foreignKey = new MCompoundForeignKey(name, refTableName, indexName);
String[] cols = SplitColumns.split(columnNames);
String[] refCols = SplitColumns.split(refColumnNames);
for (int i = 0; i < cols.length && i < refCols.length; i++) {
foreignKey.addColumnPair(cols[i], refCols[i]);
}
addForeignKey(foreignKey);
}
/**
* Construct typically from EbeanServer meta data.
*/
@@ -236,17 +265,7 @@ public class MTable {
}
for (MCompoundUniqueConstraint constraint : uniqueConstraints) {
UniqueConstraint uq = new UniqueConstraint();
uq.setName(constraint.getName());
String[] columns = constraint.getColumns();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < columns.length; i++) {
if (i > 0) {
sb.append(",");
}
sb.append(columns[i]);
}
uq.setColumnNames(sb.toString());
UniqueConstraint uq = constraint.getUniqueConstraint();
createTable.getUniqueConstraint().add(uq);
}
@@ -271,6 +290,25 @@ public class MTable {
}
}
compareColumns(modelDiff, newTable);
if (MColumn.different(comment, newTable.comment)) {
AddTableComment addTableComment = new AddTableComment();
addTableComment.setName(name);
if (newTable.comment == null) {
addTableComment.setComment(DdlHelp.DROP_COMMENT);
} else {
addTableComment.setComment(newTable.comment);
}
modelDiff.addTableComment(addTableComment);
}
compareCompoundKeys(modelDiff, newTable);
compareUniqueKeys(modelDiff, newTable);
}
private void compareColumns(ModelDiff modelDiff, MTable newTable) {
addColumn = null;
Map<String, MColumn> newColumnMap = newTable.getColumns();
@@ -303,16 +341,39 @@ public class MTable {
if (addColumn != null) {
modelDiff.addAddColumn(addColumn);
}
}
if (MColumn.different(comment, newTable.comment)) {
AddTableComment addTableComment = new AddTableComment();
addTableComment.setName(name);
if (newTable.comment == null) {
addTableComment.setComment(DdlHelp.DROP_COMMENT);
} else {
addTableComment.setComment(newTable.comment);
}
modelDiff.addTableComment(addTableComment);
private void compareCompoundKeys(ModelDiff modelDiff, MTable newTable) {
List<MCompoundForeignKey> newKeys = new ArrayList<>(newTable.getCompoundKeys());
List<MCompoundForeignKey> currentKeys = new ArrayList<>(getCompoundKeys());
// remove keys that have not changed
currentKeys.removeAll(newTable.getCompoundKeys());
newKeys.removeAll(getCompoundKeys());
for (MCompoundForeignKey currentKey : currentKeys) {
modelDiff.addAlterForeignKey(currentKey.dropForeignKey(name));
}
for (MCompoundForeignKey newKey : newKeys) {
modelDiff.addAlterForeignKey(newKey.addForeignKey(name));
}
}
private void compareUniqueKeys(ModelDiff modelDiff, MTable newTable) {
List<MCompoundUniqueConstraint> newKeys = new ArrayList<>(newTable.getUniqueConstraints());
List<MCompoundUniqueConstraint> currentKeys = new ArrayList<>(getUniqueConstraints());
// remove keys that have not changed
currentKeys.removeAll(newTable.getUniqueConstraints());
newKeys.removeAll(getUniqueConstraints());
for (MCompoundUniqueConstraint currentKey: currentKeys) {
modelDiff.addUniqueConstraint(currentKey.dropUniqueConstraint(name));
}
for (MCompoundUniqueConstraint newKey: newKeys) {
modelDiff.addUniqueConstraint(newKey.addUniqueConstraint(name));
}
}
@@ -656,6 +717,29 @@ public class MTable {
return draftTableName + "." + references.substring(lastDot + 1);
}
/**
* This method adds information which columns are nullable or not to the compound indices.
*/
public void updateCompoundIndices() {
for (MCompoundUniqueConstraint uniq : uniqueConstraints) {
List<String> nullableColumns = new ArrayList<>();
for (String columnName : uniq.getColumns()) {
MColumn col = getColumn(columnName);
if (col == null) {
throw new IllegalStateException("Column '" + columnName + "' not found in table " + getName());
}
if (!col.isNotnull()) {
nullableColumns.add(columnName);
}
}
uniq.setNullableColumns(nullableColumns.toArray(new String[nullableColumns.size()]));
}
}
public void removeForeignKey(String name) {
compoundKeys.removeIf(fk -> fk.getName().equals(name));
}
/**
* Clear the indexes on the foreign keys as they are covered by unique constraints.
*/
@@ -1,10 +1,13 @@
package io.ebeaninternal.dbmigration.model;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.ChangeSetType;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
@@ -134,6 +137,10 @@ public class ModelContainer {
applyChange((AddHistoryTable) change);
} else if (change instanceof DropHistoryTable) {
applyChange((DropHistoryTable) change);
} else if (change instanceof AddUniqueConstraint) {
applyChange((AddUniqueConstraint) change);
} else if (change instanceof AlterForeignKey) {
applyChange((AlterForeignKey) change);
} else if (change instanceof AddTableComment) {
applyChange((AddTableComment) change);
} else {
@@ -166,6 +173,34 @@ public class ModelContainer {
table.setWithHistory(false);
}
private void applyChange(AddUniqueConstraint change) {
MTable table = tables.get(change.getTableName());
if (table == null) {
throw new IllegalStateException("Table [" + change.getTableName() + "] does not exist in model?");
}
if (DdlHelp.isDropConstraint(change.getColumnNames())) {
table.getUniqueConstraints().removeIf(constraint -> constraint.getName().equals(change.getConstraintName()));
} else {
MCompoundUniqueConstraint constraint = new MCompoundUniqueConstraint(
SplitColumns.split(change.getColumnNames()), change.isOneToOne(), change.getConstraintName());
constraint.setNullableColumns(SplitColumns.split(change.getNullableColumns()));
table.getUniqueConstraints().add(constraint);
}
}
private void applyChange(AlterForeignKey change) {
MTable table = tables.get(change.getTableName());
if (table == null) {
throw new IllegalStateException("Table [" + change.getName() + "] does not exist in model?");
}
if (DdlHelp.isDropForeignKey(change.getColumnNames())) {
table.removeForeignKey(change.getName());
} else {
table.addForeignKey(change.getName(), change.getRefTableName(), change.getIndexName(), change.getColumnNames(),
change.getRefColumnNames());
}
}
private void applyChange(AddTableComment change) {
MTable table = tables.get(change.getName());
if (table == null) {
@@ -3,7 +3,9 @@ package io.ebeaninternal.dbmigration.model;
import io.ebeaninternal.dbmigration.migration.AddColumn;
import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.AlterForeignKey;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.migration.ChangeSetType;
import io.ebeaninternal.dbmigration.migration.CreateIndex;
@@ -245,4 +247,18 @@ public class ModelDiff {
public void addTableComment(AddTableComment addTableComment) {
applyChanges.add(addTableComment);
}
/**
* Adds (or drops) a unique constraint to the 'apply' changes.
*/
public void addUniqueConstraint(AddUniqueConstraint addUniqueConstraint) {
applyChanges.add(addUniqueConstraint);
}
/**
* Adds (or drops) a foreign key constraint to the 'apply' changes.
*/
public void addAlterForeignKey(AlterForeignKey alterForeignKey) {
applyChanges.add(alterForeignKey);
}
}
@@ -105,6 +105,8 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
}
addDraftTable();
table.updateCompoundIndices();
}
/**
@@ -273,6 +273,10 @@ class CQueryBuilder {
SqlLimitResponse s = buildSql(sqlSelect, request, predicates, sqlTree);
String sql = s.getSql();
if (hasMany || query.isRawSql()) {
int pos = sql.lastIndexOf(" order by "); // remove order by - mssql does not accept order by in subqueries
if (pos != -1) {
sql = sql.substring(0, pos);
}
sql = "select count(*) from ( " + sql + ")";
if (selectCountWithAlias) {
sql += " as c";
@@ -8,11 +8,12 @@ import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import io.ebean.migration.ddl.DdlRunner;
import io.ebeaninternal.dbmigration.ddlgeneration.Helper;
import org.junit.Test;
import javax.persistence.PersistenceException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -23,14 +24,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class DbMigrationTest extends BaseTestCase {
private int runScript(boolean expectErrors, String scriptName) throws IOException {
try (InputStream stream = getClass().getResourceAsStream("/dbmigration/migrationtest/" + server().getPluginApi().getDatabasePlatform().getName()+"/" + scriptName);
java.util.Scanner s = new java.util.Scanner(stream)) {
s.useDelimiter("\\A");
if (s.hasNext()) {
return runScript(expectErrors, s.next(), scriptName);
}
}
return 0;
String ddl = Helper.asText(this, "/dbmigration/migrationtest/" + server().getPluginApi().getDatabasePlatform().getName()+"/" + scriptName);
return runScript(expectErrors, ddl, scriptName);
}
private int runScript(boolean expectErrors, String content, String scriptName) {
@@ -58,35 +53,44 @@ public class DbMigrationTest extends BaseTestCase {
}
}
@IgnorePlatform({Platform.ORACLE, Platform.SQLSERVER})
@IgnorePlatform(Platform.ORACLE)
@Test
public void testRunMigration() throws IOException {
// first clean up previously created objects
runScript(true, "drop table migtest_e_ref;\n","test");
runScript(true, "drop table migtest_e_basic;\n"
+ "drop table migtest_e_history;\n"
+ "drop table migtest_e_ref;\n"
+ "drop table migtest_e_ref cascade;\n"
+ "drop table migtest_e_user;\n"
+ "drop table migtest_e_history;\n"
+ "drop table migtest_e_history cascade;\n" // pg
+ "drop table migtest_e_history_history cascade;\n" // pg
+ "drop sequence migtest_e_basic_seq;\n"
+ "drop sequence migtest_e_history_seq;\n"
+ "drop sequence migtest_e_ref_seq;\n"
+ "drop sequence migtest_e_user;\n"
+ "drop sequence migtest_e_history;\n"
, "cleanup");
cleanup("migtest_ckey_assoc",
"migtest_ckey_detail",
"migtest_ckey_parent",
"migtest_e_basic",
"migtest_e_history",
"migtest_e_history2",
"migtest_e_ref",
"migtest_e_softdelete",
"migtest_e_user",
"migtest_mtm_c",
"migtest_mtm_m",
"migtest_mtm_c_migtest_mtm_m",
"migtest_mtm_m_migtest_mtm_c",
"migtest_oto_child",
"migtest_oto_master");
runScript(false, "1.0__initial.sql");
SqlUpdate update = server().createSqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1), (2, :true, 1)");
update.setParameter("false", false);
update.setParameter("true", true);
if (isOracle()) {
SqlUpdate update = server().createSqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1)");
update.setParameter("false", false);
assertThat(server().execute(update)).isEqualTo(1);
assertThat(server().execute(update)).isEqualTo(2);
update = server().createSqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (2, :true, 1)");
update.setParameter("true", true);
assertThat(server().execute(update)).isEqualTo(1);
} else {
SqlUpdate update = server().createSqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1), (2, :true, 1)");
update.setParameter("false", false);
update.setParameter("true", true);
assertThat(server().execute(update)).isEqualTo(2);
}
// Run migration
runScript(false, "1.1.sql");
@@ -115,10 +119,19 @@ public class DbMigrationTest extends BaseTestCase {
assertThat(row.getTimestamp("some_date")).isEqualTo(new Timestamp(100, 0, 1, 0, 0, 0, 0)); // = 2000-01-01T00:00:00
// Run migration & drops
if (isMySql()) {
return; // TODO: mysql cannot drop table (need stored procedure for drop column)
}
runScript(false, "1.2__dropsFor_1.1.sql");
select = server().createSqlQuery("select * from migtest_e_basic order by id");
// Oracle caches the statement and does not detect schema change. It fails with
// an ORA-01007
if (isOracle()) {
select = server().createSqlQuery("select * from migtest_e_basic order by id,id");
} else {
select = server().createSqlQuery("select * from migtest_e_basic order by id");
}
result = select.findList();
assertThat(result).hasSize(2);
row = result.get(0);
@@ -135,4 +148,21 @@ public class DbMigrationTest extends BaseTestCase {
assertThat(row.keySet()).contains("old_boolean", "old_boolean2");
}
private void cleanup(String ... tables) {
StringBuilder sb = new StringBuilder();
for (String table : tables) {
// simple and stupid try to execute all commands on all dialects.
sb.append("alter table ").append(table).append(" set ( system_versioning = OFF );\n");
sb.append("drop table ").append(table).append(";\n");
sb.append("drop table ").append(table).append(" cascade;\n");
sb.append("drop table ").append(table).append("_history;\n");
sb.append("drop table ").append(table).append("_history cascade;\n");
sb.append("drop view ").append(table).append("_with_history;\n");
sb.append("drop sequence ").append(table).append("_seq;\n");
}
runScript(true, sb.toString(), "cleanup");
runScript(true, sb.toString(), "cleanup");
}
}
@@ -0,0 +1,22 @@
package misc.migration.v1_0;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_cascade")
public class DfkCascade {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.CASCADE)
DfkCascadeOne one;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_0;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "migtest_fk_cascade_one")
public class DfkCascadeOne {
@Id
long id;
@OneToMany(mappedBy = "one", cascade = CascadeType.ALL)
List<DfkCascade> details;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_0;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none")
public class DfkNone {
@Id
long id;
@ManyToOne
@DbForeignKey(noConstraint = true)
DfkOne one;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_0;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none_via_join")
public class DfkNoneViaJoin {
@Id
long id;
@ManyToOne
@JoinColumn(name = "one_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
DfkOne one;
}
@@ -0,0 +1,13 @@
package misc.migration.v1_0;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_one")
public class DfkOne {
@Id
long id;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_0;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_set_null")
public class DfkSetNull {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.SET_NULL)
DfkOne one;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_1;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_cascade")
public class DfkCascade {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.RESTRICT)
DfkCascadeOne one;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_1;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "migtest_fk_cascade_one")
public class DfkCascadeOne {
@Id
long id;
@OneToMany(mappedBy = "one", cascade = CascadeType.ALL)
List<DfkCascade> details;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_1;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none")
public class DfkNone {
@Id
long id;
@ManyToOne
@DbForeignKey(noConstraint = false)
DfkOne one;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_1;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none_via_join")
public class DfkNoneViaJoin {
@Id
long id;
@ManyToOne
@JoinColumn(name = "one_id", foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
DfkOne one;
}
@@ -0,0 +1,13 @@
package misc.migration.v1_1;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_one")
public class DfkOne {
@Id
long id;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_1;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_set_null")
public class DfkSetNull {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.RESTRICT)
DfkOne one;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_2;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_cascade")
public class DfkCascade {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.CASCADE)
DfkCascadeOne one;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_2;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "migtest_fk_cascade_one")
public class DfkCascadeOne {
@Id
long id;
@OneToMany(mappedBy = "one", cascade = CascadeType.ALL)
List<DfkCascade> details;
}
@@ -0,0 +1,21 @@
package misc.migration.v1_2;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none")
public class DfkNone {
@Id
long id;
@ManyToOne
@DbForeignKey(noConstraint = true)
DfkOne one;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_2;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_none_via_join")
public class DfkNoneViaJoin {
@Id
long id;
@ManyToOne
@JoinColumn(name = "one_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
DfkOne one;
}
@@ -0,0 +1,13 @@
package misc.migration.v1_2;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_one")
public class DfkOne {
@Id
long id;
}
@@ -0,0 +1,22 @@
package misc.migration.v1_2;
import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "migtest_fk_set_null")
public class DfkSetNull {
@Id
long id;
@ManyToOne
@DbForeignKey(onDelete = ConstraintMode.SET_NULL)
DfkOne one;
}
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id bigint generated by default as identity not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigint generated by default as identity not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigint generated by default as identity not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigint generated by default as identity not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigint generated by default as identity not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigint generated by default as identity not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer generated by default as identity not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -5,6 +5,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table migtest_fk_cascade drop constraint fk_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 restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -31,6 +37,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
-- NOT SUPPORTED 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';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_fk_cascade drop constraint fk_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 cascade;
alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_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 set null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status set null;
@@ -21,6 +27,11 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer auto_increment not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -5,6 +5,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_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 restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -31,6 +37,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
alter table migtest_e_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);
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_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 cascade;
alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status set null;
@@ -21,6 +27,11 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id bigint generated by default as identity (start with 1) not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigint generated by default as identity (start with 1) not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigint generated by default as identity (start with 1) not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigint generated by default as identity (start with 1) not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigint generated by default as identity (start with 1) not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigint generated by default as identity (start with 1) not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer generated by default as identity (start with 1) not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -5,6 +5,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_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 restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -31,6 +37,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
alter table migtest_e_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);
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_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 cascade;
alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status set null;
@@ -21,6 +27,11 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
@@ -2,6 +2,28 @@
<!DOCTYPE xml>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<createTable name="migtest_fk_cascade" pkName="pk_migtest_fk_cascade">
<column name="id" type="bigint" primaryKey="true"/>
<column name="one_id" type="bigint" references="migtest_fk_cascade_one.id" foreignKeyName="fk_migtest_fk_cascade_one_id" foreignKeyIndex="ix_migtest_fk_cascade_one_id" foreignKeyOnDelete="CASCADE" foreignKeyOnUpdate="RESTRICT"/>
</createTable>
<createTable name="migtest_fk_cascade_one" pkName="pk_migtest_fk_cascade_one">
<column name="id" type="bigint" primaryKey="true"/>
</createTable>
<createTable name="migtest_fk_none" pkName="pk_migtest_fk_none">
<column name="id" type="bigint" primaryKey="true"/>
<column name="one_id" type="bigint"/>
</createTable>
<createTable name="migtest_fk_none_via_join" pkName="pk_migtest_fk_none_via_join">
<column name="id" type="bigint" primaryKey="true"/>
<column name="one_id" type="bigint"/>
</createTable>
<createTable name="migtest_fk_one" pkName="pk_migtest_fk_one">
<column name="id" type="bigint" primaryKey="true"/>
</createTable>
<createTable name="migtest_fk_set_null" pkName="pk_migtest_fk_set_null">
<column name="id" type="bigint" primaryKey="true"/>
<column name="one_id" type="bigint" references="migtest_fk_one.id" foreignKeyName="fk_migtest_fk_set_null_one_id" foreignKeyIndex="ix_migtest_fk_set_null_one_id" foreignKeyOnDelete="SET_NULL" foreignKeyOnUpdate="RESTRICT"/>
</createTable>
<createTable name="migtest_e_basic" pkName="pk_migtest_e_basic">
<column name="id" type="integer" primaryKey="true"/>
<column name="status" type="varchar(1)" checkConstraint="check ( status in ('N','A','I'))" checkConstraintName="ck_migtest_e_basic_status"/>
@@ -18,8 +40,8 @@
<column name="indextest5" type="varchar(127)"/>
<column name="indextest6" type="varchar(127)"/>
<column name="user_id" type="integer" notnull="true"/>
<uniqueConstraint name="uq_migtest_e_basic_indextest2" columnNames="indextest2"/>
<uniqueConstraint name="uq_migtest_e_basic_indextest6" columnNames="indextest6"/>
<uniqueConstraint name="uq_migtest_e_basic_indextest2" columnNames="indextest2" oneToOne="false" nullableColumns="indextest2"/>
<uniqueConstraint name="uq_migtest_e_basic_indextest6" columnNames="indextest6" oneToOne="false" nullableColumns="indextest6"/>
</createTable>
<createTable name="migtest_e_history" pkName="pk_migtest_e_history">
<column name="id" type="integer" primaryKey="true"/>
@@ -2,6 +2,10 @@
<!DOCTYPE xml>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<alterColumn columnName="one_id" tableName="migtest_fk_cascade" references="migtest_fk_cascade_one.id" foreignKeyName="fk_migtest_fk_cascade_one_id" foreignKeyIndex="ix_migtest_fk_cascade_one_id" foreignKeyOnDelete="RESTRICT" foreignKeyOnUpdate="RESTRICT" dropForeignKey="fk_migtest_fk_cascade_one_id" dropForeignKeyIndex="ix_migtest_fk_cascade_one_id"/>
<alterColumn columnName="one_id" tableName="migtest_fk_none" references="migtest_fk_one.id" foreignKeyName="fk_migtest_fk_none_one_id" foreignKeyIndex="ix_migtest_fk_none_one_id" foreignKeyOnDelete="RESTRICT" foreignKeyOnUpdate="RESTRICT"/>
<alterColumn columnName="one_id" tableName="migtest_fk_none_via_join" references="migtest_fk_one.id" foreignKeyName="fk_migtest_fk_none_via_join_one_id" foreignKeyIndex="ix_migtest_fk_none_via_join_one_id"/>
<alterColumn columnName="one_id" tableName="migtest_fk_set_null" references="migtest_fk_one.id" foreignKeyName="fk_migtest_fk_set_null_one_id" foreignKeyIndex="ix_migtest_fk_set_null_one_id" foreignKeyOnDelete="RESTRICT" foreignKeyOnUpdate="RESTRICT" dropForeignKey="fk_migtest_fk_set_null_one_id" dropForeignKeyIndex="ix_migtest_fk_set_null_one_id"/>
<alterColumn columnName="status" tableName="migtest_e_basic" currentType="varchar(1)" defaultValue="'A'" notnull="true" currentNotnull="false" checkConstraint="check ( status in ('N','A','I','?'))" checkConstraintName="ck_migtest_e_basic_status"/>
<alterColumn columnName="description" tableName="migtest_e_basic" unique="uq_migtest_e_basic_description">
<before>-- rename all collisions</before>
@@ -19,6 +23,11 @@
<column name="progress" type="integer" defaultValue="0" notnull="true" checkConstraint="check ( progress in (0,1,2))" checkConstraintName="ck_migtest_e_basic_progress"/>
<column name="new_integer" type="integer" defaultValue="42" notnull="true"/>
</addColumn>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest2" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="indextest2"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest6" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="indextest6"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_name" tableName="migtest_e_basic" columnNames="name" nullableColumns="name" oneToOne="false"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest4" tableName="migtest_e_basic" columnNames="indextest4" nullableColumns="indextest4" oneToOne="false"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest5" tableName="migtest_e_basic" columnNames="indextest5" nullableColumns="indextest5" oneToOne="false"/>
<addHistoryTable baseTable="migtest_e_history"/>
<alterColumn columnName="test_string" tableName="migtest_e_history" type="bigint" currentType="varchar" currentNotnull="false" comment="Column altered to long now">
<before platforms="postgres">alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer)</before>
@@ -2,6 +2,10 @@
<!DOCTYPE xml>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<alterColumn columnName="one_id" tableName="migtest_fk_cascade" references="migtest_fk_cascade_one.id" foreignKeyName="fk_migtest_fk_cascade_one_id" foreignKeyIndex="ix_migtest_fk_cascade_one_id" foreignKeyOnDelete="CASCADE" foreignKeyOnUpdate="RESTRICT" dropForeignKey="fk_migtest_fk_cascade_one_id" dropForeignKeyIndex="ix_migtest_fk_cascade_one_id"/>
<alterColumn columnName="one_id" tableName="migtest_fk_none" dropForeignKey="fk_migtest_fk_none_one_id" dropForeignKeyIndex="ix_migtest_fk_none_one_id"/>
<alterColumn columnName="one_id" tableName="migtest_fk_none_via_join" dropForeignKey="fk_migtest_fk_none_via_join_one_id" dropForeignKeyIndex="ix_migtest_fk_none_via_join_one_id"/>
<alterColumn columnName="one_id" tableName="migtest_fk_set_null" references="migtest_fk_one.id" foreignKeyName="fk_migtest_fk_set_null_one_id" foreignKeyIndex="ix_migtest_fk_set_null_one_id" foreignKeyOnDelete="SET_NULL" foreignKeyOnUpdate="RESTRICT" dropForeignKey="fk_migtest_fk_set_null_one_id" dropForeignKeyIndex="ix_migtest_fk_set_null_one_id"/>
<alterColumn columnName="status" tableName="migtest_e_basic" currentType="varchar(1)" defaultValue="DROP DEFAULT" notnull="false" currentNotnull="true" checkConstraint="check ( status in ('N','A','I'))" checkConstraintName="ck_migtest_e_basic_status"/>
<alterColumn columnName="description" tableName="migtest_e_basic" dropUnique="uq_migtest_e_basic_description"/>
<alterColumn columnName="some_date" tableName="migtest_e_basic" currentType="timestamp" defaultValue="DROP DEFAULT" notnull="false" currentNotnull="true"/>
@@ -11,6 +15,11 @@
<column name="old_boolean2" type="boolean"/>
<column name="eref_id" type="integer" references="migtest_e_ref.id" foreignKeyName="fk_migtest_e_basic_eref_id" foreignKeyIndex="ix_migtest_e_basic_eref_id"/>
</addColumn>
<addUniqueConstraint constraintName="uq_migtest_e_basic_name" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="name"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest4" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="indextest4"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest5" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="indextest5"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest2" tableName="migtest_e_basic" columnNames="indextest2" nullableColumns="indextest2" oneToOne="false"/>
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest6" tableName="migtest_e_basic" columnNames="indextest6" nullableColumns="indextest6" oneToOne="false"/>
<alterColumn columnName="test_string" tableName="migtest_e_history" withHistory="true" comment="DROP COMMENT"/>
<addTableComment name="migtest_e_history" comment="DROP COMMENT"/>
<alterColumn columnName="test_string" tableName="migtest_e_history2" withHistory="true" currentType="varchar" defaultValue="DROP DEFAULT" notnull="false" currentNotnull="true"/>
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer auto_increment not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -5,6 +5,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table migtest_fk_cascade drop foreign key fk_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 restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_set_null drop foreign key fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic alter status set default 'A';
@@ -30,7 +36,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest6;
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 modify test_string bigint;
alter table migtest_e_history comment = 'We have history now';
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_fk_cascade drop foreign key fk_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 cascade;
alter table migtest_fk_none drop foreign key fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop foreign key fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop foreign key fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
alter table migtest_e_basic alter status drop default;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
alter table migtest_e_basic drop index uq_migtest_e_basic_description;
@@ -18,8 +24,12 @@ alter table migtest_e_basic add column old_boolean tinyint(1) default 0 not null
alter table migtest_e_basic add column old_boolean2 tinyint(1) default 0;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is '';
alter table migtest_e_history comment = 'DROP COMMENT';
alter table migtest_e_basic drop index uq_migtest_e_basic_name;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
alter table migtest_e_history comment = '';
alter table migtest_e_history2 alter test_string drop default;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
@@ -1,5 +1,45 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id number(19) not null,
one_id number(19),
constraint pk_migtest_fk_cascade primary key (id)
);
create sequence migtest_fk_cascade_seq;
create table migtest_fk_cascade_one (
id number(19) not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create sequence migtest_fk_cascade_one_seq;
create table migtest_fk_none (
id number(19) not null,
one_id number(19),
constraint pk_migtest_fk_none primary key (id)
);
create sequence migtest_fk_none_seq;
create table migtest_fk_none_via_join (
id number(19) not null,
one_id number(19),
constraint pk_migtest_fk_none_via_join primary key (id)
);
create sequence migtest_fk_none_via_join_seq;
create table migtest_fk_one (
id number(19) not null,
constraint pk_migtest_fk_one primary key (id)
);
create sequence migtest_fk_one_seq;
create table migtest_fk_set_null (
id number(19) not null,
one_id number(19),
constraint pk_migtest_fk_set_null primary key (id)
);
create sequence migtest_fk_set_null_seq;
create table migtest_e_basic (
id number(10) not null,
status varchar2(1),
@@ -52,6 +92,12 @@ create sequence migtest_e_softdelete_seq;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id);
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -6,6 +6,12 @@ create table migtest_e_user (
);
create sequence migtest_e_user_seq;
alter table migtest_fk_cascade drop constraint fk_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);
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id);
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id);
alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id);
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -14,7 +20,7 @@ alter table migtest_e_basic modify status not null;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
-- rename all collisions;
alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description);
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description);
update migtest_e_basic set some_date = '2000-01-01T00:00:00' where some_date is null;
alter table migtest_e_basic modify some_date default '2000-01-01T00:00:00';
@@ -32,6 +38,11 @@ alter table migtest_e_basic add column progress number(10) not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer number(10) not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
-- NOT YET IMPLEMENTED: 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';
alter table migtest_e_history modify test_string number(19);
comment on table migtest_e_history is 'We have history now';
@@ -6,6 +6,12 @@ create table migtest_e_ref (
);
create sequence migtest_e_ref_seq;
alter table migtest_fk_cascade drop constraint fk_migtest_fk_cascade_one_id;
alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade;
alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic modify status drop default;
alter table migtest_e_basic modify status null;
@@ -22,6 +28,11 @@ alter table migtest_e_basic add column old_boolean number(1) default 0 not null;
alter table migtest_e_basic add column old_boolean2 number(1) default 0;
alter table migtest_e_basic add column eref_id number(10);
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 modify test_string drop default;
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id bigserial not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigserial not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigserial not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigserial not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigserial not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigserial not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id serial not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -8,6 +8,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table if exists migtest_fk_cascade drop constraint if exists fk_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 restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table if exists migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -34,6 +40,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
alter table migtest_e_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 alter column test_string TYPE bigint USING (test_string::integer);
comment on column migtest_e_history.test_string is 'Column altered to long now';
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table if exists migtest_fk_cascade drop constraint if exists fk_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 cascade;
alter table if exists migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
alter table if exists migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
alter table if exists migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
@@ -21,6 +27,11 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
@@ -1,5 +1,41 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id integer not null,
one_id integer,
constraint pk_migtest_fk_cascade primary key (id),
foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update cascade
);
create table migtest_fk_cascade_one (
id integer not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id integer not null,
one_id integer,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id integer not null,
one_id integer,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id integer not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id integer not null,
one_id integer,
constraint pk_migtest_fk_set_null primary key (id),
foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null
);
create table migtest_e_basic (
id integer not null,
status varchar(1),
@@ -5,6 +5,8 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_migtest_fk_cascade_one_id;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -30,6 +32,11 @@ alter table migtest_e_basic add column progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
alter table migtest_e_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 alter column test_string integer;
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -5,6 +5,10 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_fk_cascade drop constraint if exists fk_migtest_fk_cascade_one_id;
alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status set null;
@@ -21,6 +25,11 @@ alter table migtest_e_basic add column old_boolean int default 0 not null;
alter table migtest_e_basic add column old_boolean2 int default 0;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string set null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
@@ -1,5 +1,39 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_fk_cascade (
id numeric(19) identity(1,1) not null,
one_id numeric(19),
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id numeric(19) identity(1,1) not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id numeric(19) identity(1,1) not null,
one_id numeric(19),
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id numeric(19) identity(1,1) not null,
one_id numeric(19),
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id numeric(19) identity(1,1) not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id numeric(19) identity(1,1) not null,
one_id numeric(19),
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer identity(1,1) not null,
status varchar(1),
@@ -47,6 +81,12 @@ create table migtest_e_softdelete (
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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 cascade;
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id);
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
@@ -5,6 +5,12 @@ create table migtest_e_user (
constraint pk_migtest_e_user primary key (id)
);
IF OBJECT_ID('fk_migtest_fk_cascade_one_id', 'F') IS NOT NULL alter table migtest_fk_cascade drop constraint fk_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);
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id);
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id);
IF OBJECT_ID('fk_migtest_fk_set_null_one_id', 'F') IS NOT NULL alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id);
update migtest_e_basic set status = 'A' where status is null;
IF (OBJECT_ID('ck_migtest_e_basic_status', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
@@ -31,6 +37,13 @@ alter table migtest_e_basic add progress integer not null default 0;
alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( progress in (0,1,2));
alter table migtest_e_basic add new_integer integer not null default 42;
IF (OBJECT_ID('uq_migtest_e_basic_indextest2', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_indextest2') drop index uq_migtest_e_basic_indextest2 ON migtest_e_basic;
IF (OBJECT_ID('uq_migtest_e_basic_indextest6', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_indextest6') drop index uq_migtest_e_basic_indextest6 ON migtest_e_basic;
create unique nonclustered index uq_migtest_e_basic_name on migtest_e_basic(name) where name is not null;
create unique nonclustered index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) where indextest4 is not null;
create unique nonclustered index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) where indextest5 is not null;
alter table migtest_e_history alter column test_string numeric(19);
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
@@ -5,6 +5,12 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
IF OBJECT_ID('fk_migtest_fk_cascade_one_id', 'F') IS NOT NULL alter table migtest_fk_cascade drop constraint fk_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 cascade;
IF OBJECT_ID('fk_migtest_fk_none_one_id', 'F') IS NOT NULL alter table migtest_fk_none drop constraint fk_migtest_fk_none_one_id;
IF OBJECT_ID('fk_migtest_fk_none_via_join_one_id', 'F') IS NOT NULL alter table migtest_fk_none_via_join drop constraint fk_migtest_fk_none_via_join_one_id;
IF OBJECT_ID('fk_migtest_fk_set_null_one_id', 'F') IS NOT NULL alter table migtest_fk_set_null drop constraint fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update set null;
IF (OBJECT_ID('ck_migtest_e_basic_status', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
@@ -28,6 +34,14 @@ alter table migtest_e_basic add old_boolean bit default 0 not null;
alter table migtest_e_basic add old_boolean2 bit default 0;
alter table migtest_e_basic add eref_id integer;
IF (OBJECT_ID('uq_migtest_e_basic_name', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_name') drop index uq_migtest_e_basic_name ON migtest_e_basic;
IF (OBJECT_ID('uq_migtest_e_basic_indextest4', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_indextest4') drop index uq_migtest_e_basic_indextest4 ON migtest_e_basic;
IF (OBJECT_ID('uq_migtest_e_basic_indextest5', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_indextest5') drop index uq_migtest_e_basic_indextest5 ON migtest_e_basic;
create unique nonclustered index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) where indextest2 is not null;
create unique nonclustered index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) where indextest6 is not null;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id