mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 21:15:52 +00:00
Featur/dbmigration 3 (#1118)
* ADD: more test classes for Softdelete and History * update reference models after adding test classes * DbMigration:Improved History generation for sqlserver * FIX: When DB supports Sql2011 platform, we must not alter the history-table (as this is handled by DB itself) * DbMigration: When dropping a table, drop the sequence also. * DbMigration: dropColumn is handled by platformDdl now, as SqlServerDdl needs to delete dependent objects (default constraints...) first * FIX: DbMigration is not executed on history table * DbMigration: can drop comment now. * No effective code change: completed ObjectFactory / fixed imports * FIX: drop table comment * Committed the reference models
This commit is contained in:
committed by
Rob Bygrave
parent
84d3578e33
commit
9a7646195c
@@ -3,6 +3,8 @@ package io.ebean.dbmigration.ddlgeneration.platform;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.NamingConvention;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.DbHistorySupport;
|
||||
import io.ebean.config.dbplatform.DbIdentity;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebean.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -74,6 +76,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
protected Map<String, HistoryTableUpdate> regenerateHistoryTriggers = new LinkedHashMap<>();
|
||||
|
||||
private boolean strict;
|
||||
|
||||
private final boolean sql2011History;
|
||||
|
||||
/**
|
||||
* Helper class that is used to execute the migration ddl before and after the migration action.
|
||||
@@ -196,6 +200,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
this.platformDdl = platformDdl;
|
||||
this.platformDdl.configure(serverConfig);
|
||||
this.strict = true; // TODO RPr serverConfig.getMigrationConfig().isStrict();
|
||||
DbHistorySupport hist = platformDdl.getPlatform().getHistorySupport();
|
||||
this.sql2011History = hist != null && hist.isStandardsBased();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,6 +518,14 @@ public class BaseTableDdl implements TableDdl {
|
||||
buffer.append(platformDdl.dropTable(tableName)).endOfStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'drop sequence' statement to the buffer.
|
||||
*/
|
||||
protected void dropSequence(DdlBuffer buffer, String sequenceName) throws IOException {
|
||||
|
||||
buffer.append(platformDdl.dropSequence(sequenceName)).endOfStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all the check constraints.
|
||||
*/
|
||||
@@ -715,7 +729,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
alterTableAddColumn(writer.apply(), tableName, column, false);
|
||||
}
|
||||
|
||||
if (isTrue(addColumn.isWithHistory())) {
|
||||
if (isTrue(addColumn.isWithHistory()) && !sql2011History) {
|
||||
// make same changes to the history table
|
||||
String historyTable = historyTable(tableName);
|
||||
for (Column column : columns) {
|
||||
@@ -741,6 +755,15 @@ public class BaseTableDdl implements TableDdl {
|
||||
public void generate(DdlWrite writer, DropTable dropTable) throws IOException {
|
||||
|
||||
dropTable(writer.apply(), dropTable.getName());
|
||||
|
||||
if (hasValue(dropTable.getSequenceCol())
|
||||
&& platformDdl.getPlatform().getDbIdentity().isSupportsSequence()) {
|
||||
String sequenceName = dropTable.getSequenceName();
|
||||
if (!hasValue(sequenceName)) {
|
||||
sequenceName = namingConvention.getSequenceName(dropTable.getName(), dropTable.getSequenceCol());
|
||||
}
|
||||
dropSequence(writer.apply(), sequenceName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -752,7 +775,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
String tableName = dropColumn.getTableName();
|
||||
|
||||
alterTableDropColumn(writer.apply(), tableName, dropColumn.getColumnName());
|
||||
if (isTrue(dropColumn.isWithHistory())) {
|
||||
if (isTrue(dropColumn.isWithHistory()) && !sql2011History) {
|
||||
// also drop from the history table
|
||||
regenerateHistoryTriggers(tableName, HistoryTableUpdate.Change.DROP, dropColumn.getColumnName());
|
||||
alterTableDropColumn(writer.apply(), historyTable(tableName), dropColumn.getColumnName());
|
||||
@@ -853,7 +876,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
if (hasValue(ddl)) {
|
||||
writer.apply().append(ddl).endOfStatement();
|
||||
|
||||
if (isTrue(alter.isWithHistory()) && alter.getType() != null) {
|
||||
if (isTrue(alter.isWithHistory()) && alter.getType() != null && !sql2011History) {
|
||||
// mysql and sql server column type change allowing nulls in the history table column
|
||||
AlterColumn alterHistoryColumn = new AlterColumn();
|
||||
alterHistoryColumn.setTableName(historyTable(alter.getTableName()));
|
||||
@@ -904,7 +927,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
String ddl = platformDdl.alterColumnType(alter.getTableName(), alter.getColumnName(), alter.getType());
|
||||
if (hasValue(ddl)) {
|
||||
writer.apply().append(ddl).endOfStatement();
|
||||
if (isTrue(alter.isWithHistory())) {
|
||||
if (isTrue(alter.isWithHistory()) && !sql2011History) {
|
||||
// apply same type change to matching column in the history table
|
||||
ddl = platformDdl.alterColumnType(historyTable(alter.getTableName()), alter.getColumnName(), alter.getType());
|
||||
writer.apply().append(ddl).endOfStatement();
|
||||
@@ -970,17 +993,20 @@ public class BaseTableDdl implements TableDdl {
|
||||
|
||||
|
||||
protected void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
|
||||
|
||||
buffer.append("alter table ").append(tableName).append(" drop column ").append(columnName)
|
||||
.endOfStatement();
|
||||
platformDdl.alterTableDropColumn(buffer, tableName, columnName);
|
||||
}
|
||||
|
||||
protected void alterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable) throws IOException {
|
||||
DdlMigrationHelp help = new DdlMigrationHelp(tableName, column);
|
||||
help.writeBefore(buffer);
|
||||
if (!onHistoryTable) {
|
||||
help.writeBefore(buffer);
|
||||
}
|
||||
|
||||
platformDdl.alterTableAddColumn(buffer, tableName, column, onHistoryTable, help.getDefaultValue());
|
||||
|
||||
help.writeAfter(buffer);
|
||||
if (!onHistoryTable) {
|
||||
help.writeAfter(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isFalse(Boolean value) {
|
||||
|
||||
@@ -418,6 +418,11 @@ public class PlatformDdl {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
|
||||
buffer.append("alter table ").append(tableName).append(" drop column ").append(columnName)
|
||||
.endOfStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if unique constraints for nullable columns can be inlined as normal.
|
||||
@@ -542,15 +547,19 @@ public class PlatformDdl {
|
||||
* Add table comment as a separate statement (from the create table statement).
|
||||
*/
|
||||
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException {
|
||||
|
||||
if (DdlHelp.isDropComment(tableComment)) {
|
||||
tableComment = "";
|
||||
}
|
||||
apply.append(String.format("comment on table %s is '%s'", tableName, tableComment)).endOfStatement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add column comment as a separate statement.
|
||||
*/
|
||||
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) throws IOException {
|
||||
|
||||
if (DdlHelp.isDropComment(comment)) {
|
||||
comment = "";
|
||||
}
|
||||
apply.append(String.format("comment on column %s.%s is '%s'", table, column, comment)).endOfStatement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,12 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String dropTable(String tableName) {
|
||||
return "IF OBJECT_ID('" + tableName + "', 'U') IS NOT NULL drop table " + tableName;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("IF OBJECT_ID('");
|
||||
buffer.append(tableName);
|
||||
buffer.append("', 'U') IS NOT NULL drop table ");
|
||||
buffer.append(tableName);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +81,24 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public String alterTableDropConstraint(String tableName, String constraintName) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("IF (OBJECT_ID('").append(constraintName).append("', 'C') IS NOT NULL) ");
|
||||
sb.append(super.alterTableDropConstraint(tableName, constraintName));
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* Drop a unique constraint from the table (Sometimes this is an index).
|
||||
*/
|
||||
@Override
|
||||
public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("IF (OBJECT_ID('").append(uniqueConstraintName).append("', 'UQ') IS NOT NULL) ");
|
||||
sb.append(super.alterTableDropUniqueConstraint(tableName, uniqueConstraintName)).append(";\n");
|
||||
sb.append(dropIndex(uniqueConstraintName, tableName));
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* Generate and return the create sequence DDL.
|
||||
*/
|
||||
@@ -102,13 +124,24 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String alterColumnDefaultValue(String tableName, String columnName, String defaultValue) {
|
||||
|
||||
// Unfortunately, the SqlServer creates default values with a random name.
|
||||
// You can specify a name in DDL, but this does not work in conjunction with
|
||||
// temporal tables in certain cases. So we have to delete the constraint with
|
||||
// a rather complex statement.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (DdlHelp.isDropDefault(defaultValue)) {
|
||||
return "alter table " + tableName + " drop constraint df_" + tableName + "_" + columnName;
|
||||
sb.append("delimiter $$\n");
|
||||
sb.append("DECLARE @Tmp nvarchar(200);");
|
||||
sb.append("select @Tmp = t1.name from sys.default_constraints t1\n");
|
||||
sb.append(" join sys.columns t2 on t1.object_id = t2.default_object_id\n");
|
||||
sb.append(" where t1.parent_object_id = OBJECT_ID('").append(tableName)
|
||||
.append("') and t2.name = '").append(columnName).append("';\n");
|
||||
sb.append("if @Tmp is not null EXEC('alter table ").append(tableName).append(" drop constraint ' + @Tmp)$$");
|
||||
} else {
|
||||
return "alter table " + tableName + " add constraint df_" + tableName + "_" + columnName
|
||||
+ " default " + defaultValue + " for " + columnName;
|
||||
sb.append("alter table ").append(tableName);
|
||||
sb.append(" add default ").append(defaultValue).append(" for ").append(columnName);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,4 +190,28 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
|
||||
// do nothing for MS SQL Server (cause it requires stored procedures etc)
|
||||
}
|
||||
|
||||
/**
|
||||
* It is rather complex to delete a column on SqlServer as there must not exist any references
|
||||
* (constraints, default values, indices and foreign keys). The list is not yet complete, as
|
||||
* indices over multiple columns will not yet deleted.
|
||||
* (This may be changed to delete all refering objects by using the sys.* tables later)
|
||||
*/
|
||||
@Override
|
||||
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
|
||||
buffer.append("-- drop column ").append(tableName).append(".").append(columnName).endOfStatement();
|
||||
|
||||
buffer.append(alterTableDropUniqueConstraint(tableName, naming.uniqueConstraintName(tableName, columnName)));
|
||||
buffer.endOfStatement();
|
||||
buffer.append(alterColumnDefaultValue(tableName, columnName, DdlHelp.DROP_DEFAULT));
|
||||
buffer.endOfStatement();
|
||||
buffer.append(alterTableDropConstraint(tableName, naming.checkConstraintName(tableName, columnName)));
|
||||
buffer.endOfStatement();
|
||||
buffer.append(dropIndex(naming.indexName(tableName, columnName), tableName));
|
||||
buffer.endOfStatement();
|
||||
buffer.append(alterTableDropForeignKey(tableName, naming.foreignKeyConstraintName(tableName, columnName)));
|
||||
buffer.endOfStatement();
|
||||
super.alterTableDropColumn(buffer, tableName, columnName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebean.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebean.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -16,11 +17,13 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
private String systemPeriodStart;
|
||||
private String systemPeriodEnd;
|
||||
private PlatformDdl platformDdl;
|
||||
|
||||
@Override
|
||||
public void configure(ServerConfig serverConfig, PlatformDdl platformDdl) {
|
||||
this.systemPeriodStart = serverConfig.getAsOfSysPeriod() + "From";
|
||||
this.systemPeriodEnd = serverConfig.getAsOfSysPeriod() + "To";
|
||||
this.platformDdl = platformDdl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,9 +55,19 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
|
||||
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
|
||||
String baseTable = dropHistoryTable.getBaseTable();
|
||||
DdlBuffer apply = writer.applyHistory();
|
||||
apply.append("-- dropping history support for ").append(baseTable).endOfStatement();
|
||||
// drop default constraints
|
||||
|
||||
apply.append(platformDdl.alterColumnDefaultValue(baseTable, systemPeriodStart, DdlHelp.DROP_DEFAULT)).endOfStatement();
|
||||
apply.append(platformDdl.alterColumnDefaultValue(baseTable, systemPeriodEnd, DdlHelp.DROP_DEFAULT)).endOfStatement();
|
||||
// switch of versioning & period
|
||||
apply.append("alter table ").append(baseTable).append(" set (system_versioning = off)").endOfStatement();
|
||||
apply.append("alter table ").append(baseTable).append(" drop period for system_time").endOfStatement();
|
||||
// now drop tables & columns
|
||||
apply.append("alter table ").append(baseTable).append(" drop column ").append(systemPeriodStart).endOfStatement();
|
||||
apply.append("alter table ").append(baseTable).append(" drop column ").append(systemPeriodEnd).endOfStatement();
|
||||
apply.append("IF OBJECT_ID('").append(baseTable).append("_history', 'U') IS NOT NULL drop table ").append(baseTable).append("_history").endOfStatement();
|
||||
apply.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,6 @@ import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,10 @@ public class DropTable {
|
||||
|
||||
@XmlAttribute(name = "name", required = true)
|
||||
protected String name;
|
||||
@XmlAttribute(name = "sequenceCol")
|
||||
protected String sequenceCol;
|
||||
@XmlAttribute(name = "sequenceName")
|
||||
protected String sequenceName;
|
||||
|
||||
/**
|
||||
* Gets the value of the name property.
|
||||
@@ -50,4 +54,44 @@ public class DropTable {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the sequenceCol property.
|
||||
*
|
||||
* @return possible object is
|
||||
* {@link String }
|
||||
*/
|
||||
public String getSequenceCol() {
|
||||
return sequenceCol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the sequenceName property.
|
||||
*
|
||||
* @return possible object is
|
||||
* {@link String }
|
||||
*/
|
||||
public String getSequenceName() {
|
||||
return sequenceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the sequenceCol property.
|
||||
*
|
||||
* @param value allowed object is
|
||||
* {@link String }
|
||||
*/
|
||||
public void setSequenceCol(String value) {
|
||||
this.sequenceCol = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the sequenceName property.
|
||||
*
|
||||
* @param value allowed object is
|
||||
* {@link String }
|
||||
*/
|
||||
public void setSequenceName(String value) {
|
||||
this.sequenceName = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -186,5 +186,13 @@ public class ObjectFactory {
|
||||
public Migration createMigration() {
|
||||
return new Migration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DdlScript }
|
||||
*/
|
||||
public DdlScript createDdlScript() {
|
||||
return new DdlScript();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package io.ebean.dbmigration.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sound.midi.MidiDevice.Info;
|
||||
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.DdlHelp;
|
||||
import io.ebean.dbmigration.migration.AlterColumn;
|
||||
import io.ebean.dbmigration.migration.Column;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebean.dbmigration.model;
|
||||
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.DdlHelp;
|
||||
import io.ebean.dbmigration.migration.AddColumn;
|
||||
import io.ebean.dbmigration.migration.AddHistoryTable;
|
||||
import io.ebean.dbmigration.migration.AddTableComment;
|
||||
@@ -180,6 +181,24 @@ public class MTable {
|
||||
public DropTable dropTable() {
|
||||
DropTable dropTable = new DropTable();
|
||||
dropTable.setName(name);
|
||||
// we must add pk col name & sequence name, as we have to delete the sequence also.
|
||||
if (identityType != IdentityType.GENERATOR && identityType != IdentityType.EXTERNAL) {
|
||||
String pkCol = null;
|
||||
for (MColumn column : columns.values()) {
|
||||
if (column.isPrimaryKey()) {
|
||||
if (pkCol == null) {
|
||||
pkCol = column.getName();
|
||||
} else { // multiple pk cols -> no sequence
|
||||
pkCol = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pkCol != null) {
|
||||
dropTable.setSequenceCol(pkCol);
|
||||
dropTable.setSequenceName(sequenceName);
|
||||
}
|
||||
}
|
||||
return dropTable;
|
||||
}
|
||||
|
||||
@@ -288,7 +307,11 @@ public class MTable {
|
||||
if (MColumn.different(comment, newTable.comment)) {
|
||||
AddTableComment addTableComment = new AddTableComment();
|
||||
addTableComment.setName(name);
|
||||
addTableComment.setComment(newTable.comment);
|
||||
if (newTable.comment == null) {
|
||||
addTableComment.setComment(DdlHelp.DROP_COMMENT);
|
||||
} else {
|
||||
addTableComment.setComment(newTable.comment);
|
||||
}
|
||||
modelDiff.addTableComment(addTableComment);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,5 +1,7 @@
|
||||
package io.ebean.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
|
||||
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
|
||||
@@ -11,7 +13,6 @@ import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
@@ -21,6 +22,10 @@ public class PlatformDdl_AlterColumnTest {
|
||||
PlatformDdl oraDdl = new OraclePlatform().getPlatformDdl();
|
||||
PlatformDdl sqlServerDdl = new SqlServerPlatform().getPlatformDdl();
|
||||
|
||||
{
|
||||
ServerConfig serverConfig = Ebean.getDefaultServer().getPluginApi().getServerConfig();
|
||||
sqlServerDdl.configure(serverConfig);
|
||||
}
|
||||
AlterColumn alterNotNull() {
|
||||
AlterColumn alterColumn = new AlterColumn();
|
||||
alterColumn.setTableName("mytab");
|
||||
@@ -157,7 +162,7 @@ public class PlatformDdl_AlterColumnTest {
|
||||
assertEquals("alter table mytab alter acol set default 'hi'", sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "'hi'");
|
||||
assertEquals("alter table mytab add constraint df_mytab_acol default 'hi' for acol", sql);
|
||||
assertEquals("alter table mytab add default 'hi' for acol", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +181,7 @@ public class PlatformDdl_AlterColumnTest {
|
||||
assertEquals("alter table mytab alter acol drop default", sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "DROP DEFAULT");
|
||||
assertEquals("alter table mytab drop constraint df_mytab_acol", sql);
|
||||
assertThat(sql).startsWith("delimiter $$").endsWith("$$");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@ public class PlatformDdl_dropUniqueConstraintTest {
|
||||
sql = oraDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
assertEquals("alter table mytab drop constraint uq_name", sql);
|
||||
sql = sqlServerDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
assertEquals("alter table mytab drop constraint uq_name", sql);
|
||||
assertEquals("IF (OBJECT_ID('uq_name', 'UQ') IS NOT NULL) alter table mytab drop constraint uq_name;\n"
|
||||
+ "IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('mytab','U') AND name = 'uq_name') drop index uq_name ON mytab", sql);
|
||||
|
||||
|
||||
sql = mysqlDdl.alterTableDropUniqueConstraint("mytab", "uq_name");
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package misc.migration.v1_0;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.History;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_history2")
|
||||
@History
|
||||
public class EHistory2 {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
|
||||
String testString;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package misc.migration.v1_0;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_softdelete")
|
||||
public class ESoftdelete {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
|
||||
String testString;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package misc.migration.v1_1;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.DbDefault;
|
||||
import io.ebean.annotation.History;
|
||||
import io.ebean.annotation.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_history2")
|
||||
@History
|
||||
public class EHistory2 {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
@NotNull
|
||||
@DbDefault("unknown")
|
||||
String testString;
|
||||
|
||||
String testString2;
|
||||
|
||||
@NotNull
|
||||
@DbDefault("unknown")
|
||||
String testString3;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package misc.migration.v1_1;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_softdelete")
|
||||
public class ESoftdelete {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
|
||||
String testString;
|
||||
|
||||
@SoftDelete
|
||||
boolean deleted;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package misc.migration.v1_2;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.History;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_history2")
|
||||
@History
|
||||
public class EHistory2 {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
|
||||
String testString;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package misc.migration.v1_2;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_softdelete")
|
||||
public class ESoftdelete {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
|
||||
String testString;
|
||||
}
|
||||
@@ -27,11 +27,23 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer generated by default as identity not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer generated by default as identity not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer generated by default as identity not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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;
|
||||
|
||||
@@ -33,6 +33,17 @@ 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_history alter column test_string bigint;
|
||||
comment on table migtest_e_history is 'We have history now';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter column test_string set default 'unknown';
|
||||
alter table migtest_e_history2 alter column test_string set not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted boolean not null default false;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index ix_migtest_e_basic_indextest1;
|
||||
|
||||
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
drop table migtest_e_ref;
|
||||
drop sequence migtest_e_ref_seq;
|
||||
|
||||
@@ -20,7 +20,10 @@ 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;
|
||||
|
||||
comment on column migtest_e_history.test_string is 'DROP COMMENT';
|
||||
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;
|
||||
alter table migtest_e_history2 alter column test_string set null;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -9,4 +9,13 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table migtest_e_user;
|
||||
drop sequence migtest_e_user_seq;
|
||||
|
||||
@@ -27,13 +27,36 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer auto_increment not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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);
|
||||
|
||||
alter table migtest_e_history2 add column sys_period_start datetime(6) default now(6);
|
||||
alter table migtest_e_history2 add column sys_period_end datetime(6);
|
||||
create table migtest_e_history2_history(
|
||||
id integer,
|
||||
test_string varchar(255),
|
||||
sys_period_start datetime(6),
|
||||
sys_period_end datetime(6)
|
||||
);
|
||||
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
|
||||
|
||||
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
|
||||
|
||||
@@ -33,6 +33,17 @@ 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_history alter column test_string bigint;
|
||||
comment on table migtest_e_history is 'We have history now';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter column test_string set default 'unknown';
|
||||
alter table migtest_e_history2 alter column test_string set not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted boolean not null default false;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index if exists ix_migtest_e_basic_indextest1;
|
||||
@@ -48,3 +59,6 @@ create table migtest_e_history_history(
|
||||
create view migtest_e_history_with_history as select * from migtest_e_history union all select * from migtest_e_history_history;
|
||||
|
||||
create trigger migtest_e_history_history_upd before update,delete on migtest_e_history for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
|
||||
-- changes: [add test_string2, add test_string3]
|
||||
drop trigger migtest_e_history2_history_upd;
|
||||
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
|
||||
|
||||
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
drop table if exists migtest_e_ref;
|
||||
drop sequence if exists migtest_e_ref_seq;
|
||||
|
||||
@@ -20,7 +20,10 @@ 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;
|
||||
|
||||
comment on column migtest_e_history.test_string is 'DROP COMMENT';
|
||||
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;
|
||||
alter table migtest_e_history2 alter column test_string set null;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index if exists ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -17,4 +17,16 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table if exists migtest_e_user;
|
||||
drop sequence if exists migtest_e_user_seq;
|
||||
-- changes: [drop test_string2, drop test_string3]
|
||||
drop trigger migtest_e_history2_history_upd;
|
||||
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
|
||||
|
||||
@@ -27,11 +27,23 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer generated by default as identity (start with 1) not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer generated by default as identity (start with 1) not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer generated by default as identity (start with 1) not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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;
|
||||
|
||||
@@ -33,6 +33,17 @@ 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_history alter column test_string bigint;
|
||||
comment on table migtest_e_history is 'We have history now';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter column test_string set default 'unknown';
|
||||
alter table migtest_e_history2 alter column test_string set not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted boolean not null default false;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index if exists ix_migtest_e_basic_indextest1;
|
||||
|
||||
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
drop table if exists migtest_e_ref;
|
||||
drop sequence if exists migtest_e_ref_seq;
|
||||
|
||||
@@ -20,7 +20,10 @@ 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;
|
||||
|
||||
comment on column migtest_e_history.test_string is 'DROP COMMENT';
|
||||
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;
|
||||
alter table migtest_e_history2 alter column test_string set null;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index if exists ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -9,4 +9,13 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table if exists migtest_e_user;
|
||||
drop sequence if exists migtest_e_user_seq;
|
||||
|
||||
@@ -25,9 +25,17 @@
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="test_string" type="varchar"/>
|
||||
</createTable>
|
||||
<createTable name="migtest_e_history2" withHistory="true" pkName="pk_migtest_e_history2">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="test_string" type="varchar"/>
|
||||
</createTable>
|
||||
<createTable name="migtest_e_ref" pkName="pk_migtest_e_ref">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
</createTable>
|
||||
<createTable name="migtest_e_softdelete" pkName="pk_migtest_e_softdelete">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="test_string" type="varchar"/>
|
||||
</createTable>
|
||||
<createIndex indexName="ix_migtest_e_basic_indextest1" tableName="migtest_e_basic" columns="indextest1"/>
|
||||
<createIndex indexName="ix_migtest_e_basic_indextest5" tableName="migtest_e_basic" columns="indextest5"/>
|
||||
</changeSet>
|
||||
|
||||
@@ -24,6 +24,14 @@
|
||||
<before platforms="postgres">alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer)</before>
|
||||
</alterColumn>
|
||||
<addTableComment name="migtest_e_history" comment="We have history now"/>
|
||||
<alterColumn columnName="test_string" tableName="migtest_e_history2" withHistory="true" currentType="varchar" defaultValue="'unknown'" notnull="true" currentNotnull="false"/>
|
||||
<addColumn tableName="migtest_e_history2" withHistory="true">
|
||||
<column name="test_string2" type="varchar"/>
|
||||
<column name="test_string3" type="varchar" defaultValue="'unknown'" notnull="true"/>
|
||||
</addColumn>
|
||||
<addColumn tableName="migtest_e_softdelete">
|
||||
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
|
||||
</addColumn>
|
||||
<createTable name="migtest_e_user" pkName="pk_migtest_e_user">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
</createTable>
|
||||
@@ -36,6 +44,6 @@
|
||||
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
|
||||
<dropTable name="migtest_e_ref"/>
|
||||
<dropTable name="migtest_e_ref" sequenceCol="id"/>
|
||||
</changeSet>
|
||||
</migration>
|
||||
@@ -5,6 +5,6 @@
|
||||
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
|
||||
<dropTable name="migtest_e_ref"/>
|
||||
<dropTable name="migtest_e_ref" sequenceCol="id"/>
|
||||
</changeSet>
|
||||
</migration>
|
||||
@@ -12,7 +12,8 @@
|
||||
<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>
|
||||
<alterColumn columnName="test_string" tableName="migtest_e_history" withHistory="true" comment="DROP COMMENT"/>
|
||||
<addTableComment name="migtest_e_history"/>
|
||||
<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"/>
|
||||
<createTable name="migtest_e_ref" pkName="pk_migtest_e_ref">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
</createTable>
|
||||
@@ -28,6 +29,9 @@
|
||||
<dropColumn columnName="progress" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="new_integer" tableName="migtest_e_basic"/>
|
||||
<dropHistoryTable baseTable="migtest_e_history"/>
|
||||
<dropTable name="migtest_e_user"/>
|
||||
<dropColumn columnName="test_string2" tableName="migtest_e_history2" withHistory="true"/>
|
||||
<dropColumn columnName="test_string3" tableName="migtest_e_history2" withHistory="true"/>
|
||||
<dropColumn columnName="deleted" tableName="migtest_e_softdelete"/>
|
||||
<dropTable name="migtest_e_user" sequenceCol="id"/>
|
||||
</changeSet>
|
||||
</migration>
|
||||
@@ -8,6 +8,9 @@
|
||||
<dropColumn columnName="progress" tableName="migtest_e_basic"/>
|
||||
<dropColumn columnName="new_integer" tableName="migtest_e_basic"/>
|
||||
<dropHistoryTable baseTable="migtest_e_history"/>
|
||||
<dropTable name="migtest_e_user"/>
|
||||
<dropColumn columnName="test_string2" tableName="migtest_e_history2" withHistory="true"/>
|
||||
<dropColumn columnName="test_string3" tableName="migtest_e_history2" withHistory="true"/>
|
||||
<dropColumn columnName="deleted" tableName="migtest_e_softdelete"/>
|
||||
<dropTable name="migtest_e_user" sequenceCol="id"/>
|
||||
</changeSet>
|
||||
</migration>
|
||||
@@ -27,13 +27,44 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer auto_increment not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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);
|
||||
|
||||
alter table migtest_e_history2 add column sys_period_start datetime(6) default now(6);
|
||||
alter table migtest_e_history2 add column sys_period_end datetime(6);
|
||||
create table migtest_e_history2_history(
|
||||
id integer,
|
||||
test_string varchar(255),
|
||||
sys_period_start datetime(6),
|
||||
sys_period_end datetime(6)
|
||||
);
|
||||
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
|
||||
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
|
||||
set NEW.sys_period_start = now(6);
|
||||
end$$
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
|
||||
end$$
|
||||
|
||||
@@ -32,6 +32,17 @@ 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_history modify test_string bigint;
|
||||
alter table migtest_e_history comment = 'We have history now';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter test_string set default 'unknown';
|
||||
alter table migtest_e_history2 modify test_string varchar(255) not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted tinyint(1) default 0 not null;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index ix_migtest_e_basic_indextest1 on migtest_e_basic;
|
||||
@@ -55,3 +66,17 @@ delimiter $$
|
||||
create trigger migtest_e_history_history_del before delete on migtest_e_history for each row begin
|
||||
insert into migtest_e_history_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
|
||||
end$$
|
||||
-- changes: [add test_string2, add test_string3]
|
||||
lock tables migtest_e_history2 write;
|
||||
drop trigger migtest_e_history2_history_upd;
|
||||
drop trigger migtest_e_history2_history_del;
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string, test_string2, test_string3) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
|
||||
set NEW.sys_period_start = now(6);
|
||||
end$$
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string, test_string2, test_string3) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
|
||||
end$$
|
||||
unlock tables;
|
||||
|
||||
@@ -17,7 +17,9 @@ 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 'DROP COMMENT';
|
||||
comment on column migtest_e_history.test_string is '';
|
||||
alter table migtest_e_history comment = 'DROP 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);
|
||||
drop index ix_migtest_e_basic_indextest3 on migtest_e_basic;
|
||||
|
||||
@@ -18,4 +18,26 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table if exists migtest_e_user;
|
||||
-- changes: [drop test_string2, drop test_string3]
|
||||
lock tables migtest_e_history2 write;
|
||||
drop trigger migtest_e_history2_history_upd;
|
||||
drop trigger migtest_e_history2_history_del;
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
|
||||
set NEW.sys_period_start = now(6);
|
||||
end$$
|
||||
delimiter $$
|
||||
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
|
||||
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
|
||||
end$$
|
||||
unlock tables;
|
||||
|
||||
@@ -29,12 +29,26 @@ create table migtest_e_history (
|
||||
);
|
||||
create sequence migtest_e_history_seq;
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id number(10) not null,
|
||||
test_string varchar2(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
create sequence migtest_e_history2_seq;
|
||||
|
||||
create table migtest_e_ref (
|
||||
id number(10) not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
create sequence migtest_e_ref_seq;
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id number(10) not null,
|
||||
test_string varchar2(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
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_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id);
|
||||
|
||||
@@ -34,6 +34,15 @@ alter table migtest_e_basic add column new_integer number(10) not null default 4
|
||||
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';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 modify test_string default 'unknown';
|
||||
alter table migtest_e_history2 modify test_string not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar2(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar2(255) not null default 'unknown';
|
||||
|
||||
alter table migtest_e_softdelete add column deleted number(1) default 0 not null;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index ix_migtest_e_basic_indextest1;
|
||||
|
||||
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
drop table migtest_e_ref cascade constraints purge;
|
||||
drop sequence migtest_e_ref_seq;
|
||||
|
||||
@@ -21,7 +21,10 @@ 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);
|
||||
|
||||
comment on column migtest_e_history.test_string is 'DROP COMMENT';
|
||||
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;
|
||||
alter table migtest_e_history2 modify test_string null;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -9,4 +9,11 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table migtest_e_user cascade constraints purge;
|
||||
drop sequence migtest_e_user_seq;
|
||||
|
||||
@@ -27,13 +27,46 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id serial not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id serial not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id serial not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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);
|
||||
|
||||
alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null);
|
||||
create table migtest_e_history2_history(like migtest_e_history2);
|
||||
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
|
||||
|
||||
create or replace function migtest_e_history2_history_version() returns trigger as $$
|
||||
begin
|
||||
if (TG_OP = 'UPDATE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
NEW.sys_period = tstzrange(current_timestamp,null);
|
||||
return new;
|
||||
elsif (TG_OP = 'DELETE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
return old;
|
||||
end if;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
create trigger migtest_e_history2_history_upd
|
||||
before update or delete on migtest_e_history2
|
||||
for each row execute procedure migtest_e_history2_history_version();
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
-- drop dependencies
|
||||
drop view if exists migtest_e_history2_with_history;
|
||||
|
||||
-- apply changes
|
||||
create table migtest_e_user (
|
||||
id serial not null,
|
||||
@@ -35,6 +38,17 @@ alter table migtest_e_history alter column test_string TYPE bigint USING (test_s
|
||||
comment on column migtest_e_history.test_string is 'Column altered to long now';
|
||||
alter table migtest_e_history alter column test_string type bigint;
|
||||
comment on table migtest_e_history is 'We have history now';
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter column test_string set default 'unknown';
|
||||
alter table migtest_e_history2 alter column test_string set not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted boolean not null default false;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index if exists ix_migtest_e_basic_indextest1;
|
||||
@@ -60,3 +74,19 @@ create trigger migtest_e_history_history_upd
|
||||
before update or delete on migtest_e_history
|
||||
for each row execute procedure migtest_e_history_history_version();
|
||||
|
||||
-- changes: [add test_string2, add test_string3]
|
||||
create or replace view migtest_e_history2_with_history as select id, test_string, test_string2, test_string3, sys_period from migtest_e_history2 union all select id, test_string, test_string2, test_string3, sys_period from migtest_e_history2_history;
|
||||
|
||||
create or replace function migtest_e_history2_history_version() returns trigger as $$
|
||||
begin
|
||||
if (TG_OP = 'UPDATE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string, test_string2, test_string3) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
|
||||
NEW.sys_period = tstzrange(current_timestamp,null);
|
||||
return new;
|
||||
elsif (TG_OP = 'DELETE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string, test_string2, test_string3) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
|
||||
return old;
|
||||
end if;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
drop table if exists migtest_e_ref cascade;
|
||||
drop sequence if exists migtest_e_ref_seq;
|
||||
|
||||
@@ -20,7 +20,10 @@ 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;
|
||||
|
||||
comment on column migtest_e_history.test_string is 'DROP COMMENT';
|
||||
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;
|
||||
alter table migtest_e_history2 alter column test_string drop not null;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index if exists ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -6,6 +6,7 @@ drop view migtest_e_history_with_history;
|
||||
alter table migtest_e_history drop column sys_period;
|
||||
drop table migtest_e_history_history;
|
||||
|
||||
drop view if exists migtest_e_history2_with_history;
|
||||
|
||||
-- apply changes
|
||||
alter table migtest_e_basic drop column new_string_field;
|
||||
@@ -18,4 +19,29 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table if exists migtest_e_user cascade;
|
||||
drop sequence if exists migtest_e_user_seq;
|
||||
-- changes: [drop test_string2, drop test_string3]
|
||||
create or replace view migtest_e_history2_with_history as select id, test_string, sys_period from migtest_e_history2 union all select id, test_string, sys_period from migtest_e_history2_history;
|
||||
|
||||
create or replace function migtest_e_history2_history_version() returns trigger as $$
|
||||
begin
|
||||
if (TG_OP = 'UPDATE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
NEW.sys_period = tstzrange(current_timestamp,null);
|
||||
return new;
|
||||
elsif (TG_OP = 'DELETE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
return old;
|
||||
end if;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
@@ -28,10 +28,22 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
|
||||
@@ -30,6 +30,17 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p
|
||||
alter table migtest_e_basic add column new_integer integer not null default 42;
|
||||
|
||||
alter table migtest_e_history alter column test_string integer;
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 alter column test_string set default 'unknown';
|
||||
alter table migtest_e_history2 alter column test_string set not null;
|
||||
alter table migtest_e_history2 add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
|
||||
alter table migtest_e_history2_history add column test_string2 varchar(255);
|
||||
alter table migtest_e_history2_history add column test_string3 varchar(255);
|
||||
|
||||
alter table migtest_e_softdelete add column deleted int default 0 not null;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
drop index if exists ix_migtest_e_basic_indextest1;
|
||||
|
||||
@@ -20,6 +20,8 @@ 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_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);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
drop index if exists ix_migtest_e_basic_indextest3;
|
||||
|
||||
@@ -9,4 +9,12 @@ alter table migtest_e_basic drop column progress;
|
||||
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
alter table migtest_e_history2_history drop column test_string2;
|
||||
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
alter table migtest_e_history2_history drop column test_string3;
|
||||
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
drop table if exists migtest_e_user;
|
||||
|
||||
@@ -27,13 +27,30 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id integer identity(1,1) not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id integer identity(1,1) not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id integer identity(1,1) not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
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_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);
|
||||
|
||||
alter table migtest_e_history2
|
||||
add sys_periodFrom datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(),
|
||||
sys_periodTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999',
|
||||
period for system_time (sys_periodFrom, sys_periodTo);
|
||||
alter table migtest_e_history2 set (system_versioning = on (history_table=dbo.migtest_e_history2_history));
|
||||
|
||||
@@ -6,8 +6,8 @@ create table migtest_e_user (
|
||||
|
||||
|
||||
update migtest_e_basic set status = 'A' where status is null;
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic add constraint df_migtest_e_basic_status default 'A' for status;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_status', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic add default 'A' for status;
|
||||
alter table migtest_e_basic alter column status varchar(1) not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
|
||||
|
||||
@@ -15,7 +15,7 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( sta
|
||||
create unique nonclustered index uq_migtest_e_basic_description on migtest_e_basic(description) where description is not null;
|
||||
|
||||
update migtest_e_basic set some_date = '2000-01-01T00:00:00' where some_date is null;
|
||||
alter table migtest_e_basic add constraint df_migtest_e_basic_some_date default '2000-01-01T00:00:00' for some_date;
|
||||
alter table migtest_e_basic add default '2000-01-01T00:00:00' for some_date;
|
||||
alter table migtest_e_basic alter column some_date datetime2 not null;
|
||||
|
||||
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
|
||||
@@ -31,6 +31,15 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p
|
||||
alter table migtest_e_basic add new_integer integer not null default 42;
|
||||
|
||||
alter table migtest_e_history alter column test_string numeric(19);
|
||||
|
||||
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
|
||||
alter table migtest_e_history2 add default 'unknown' for test_string;
|
||||
alter table migtest_e_history2 alter column test_string varchar(255) not null;
|
||||
alter table migtest_e_history2 add test_string2 varchar(255);
|
||||
alter table migtest_e_history2 add test_string3 varchar(255) not null default 'unknown';
|
||||
|
||||
alter table migtest_e_softdelete add deleted bit default 0 not null;
|
||||
|
||||
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
|
||||
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_indextest1') drop index ix_migtest_e_basic_indextest1 ON migtest_e_basic;
|
||||
|
||||
@@ -1,8 +1,41 @@
|
||||
-- apply changes
|
||||
-- drop column migtest_e_basic.old_boolean;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_old_boolean', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_old_boolean;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_old_boolean') drop index uq_migtest_e_basic_old_boolean ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'old_boolean';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_old_boolean', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_old_boolean;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_old_boolean') drop index ix_migtest_e_basic_old_boolean ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_old_boolean', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_old_boolean;
|
||||
alter table migtest_e_basic drop column old_boolean;
|
||||
|
||||
-- drop column migtest_e_basic.old_boolean2;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_old_boolean2', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_old_boolean2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_old_boolean2') drop index uq_migtest_e_basic_old_boolean2 ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'old_boolean2';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_old_boolean2', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_old_boolean2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_old_boolean2') drop index ix_migtest_e_basic_old_boolean2 ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_old_boolean2', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_old_boolean2;
|
||||
alter table migtest_e_basic drop column old_boolean2;
|
||||
|
||||
-- drop column migtest_e_basic.eref_id;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_eref_id', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_eref_id;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_eref_id') drop index uq_migtest_e_basic_eref_id ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'eref_id';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_eref_id', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_eref_id;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_eref_id') drop index ix_migtest_e_basic_eref_id ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_eref_id', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_eref_id;
|
||||
alter table migtest_e_basic drop column eref_id;
|
||||
|
||||
IF OBJECT_ID('migtest_e_ref', 'U') IS NOT NULL drop table migtest_e_ref;
|
||||
|
||||
@@ -4,20 +4,34 @@ create table migtest_e_ref (
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic drop constraint df_migtest_e_basic_status;
|
||||
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
|
||||
join sys.columns t2 on t1.object_id = t2.default_object_id
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'status';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
|
||||
alter table migtest_e_basic drop constraint uq_migtest_e_basic_description;
|
||||
alter table migtest_e_basic drop constraint df_migtest_e_basic_some_date;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_description', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_description;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_description') drop index uq_migtest_e_basic_description ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'some_date';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
|
||||
update migtest_e_basic set user_id = 23 where user_id is null;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_user_id', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id;
|
||||
alter table migtest_e_basic add constraint df_migtest_e_basic_user_id default 23 for user_id;
|
||||
alter table migtest_e_basic add default 23 for user_id;
|
||||
alter table migtest_e_basic alter column user_id integer not null;
|
||||
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;
|
||||
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_indextest3') drop index ix_migtest_e_basic_indextest3 ON migtest_e_basic;
|
||||
|
||||
@@ -1,15 +1,123 @@
|
||||
-- apply changes
|
||||
-- drop column migtest_e_basic.new_string_field;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_new_string_field', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_string_field;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_string_field') drop index uq_migtest_e_basic_new_string_field ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_string_field';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_new_string_field', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_string_field;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_string_field') drop index ix_migtest_e_basic_new_string_field ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_new_string_field', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_string_field;
|
||||
alter table migtest_e_basic drop column new_string_field;
|
||||
|
||||
-- drop column migtest_e_basic.new_boolean_field;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_new_boolean_field', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_boolean_field;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_boolean_field') drop index uq_migtest_e_basic_new_boolean_field ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_boolean_field';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_new_boolean_field', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_boolean_field;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_boolean_field') drop index ix_migtest_e_basic_new_boolean_field ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_new_boolean_field', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_boolean_field;
|
||||
alter table migtest_e_basic drop column new_boolean_field;
|
||||
|
||||
-- drop column migtest_e_basic.new_boolean_field2;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_new_boolean_field2', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_boolean_field2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_boolean_field2') drop index uq_migtest_e_basic_new_boolean_field2 ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_boolean_field2';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_new_boolean_field2', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_boolean_field2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_boolean_field2') drop index ix_migtest_e_basic_new_boolean_field2 ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_new_boolean_field2', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_boolean_field2;
|
||||
alter table migtest_e_basic drop column new_boolean_field2;
|
||||
|
||||
-- drop column migtest_e_basic.progress;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_progress', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_progress;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_progress') drop index uq_migtest_e_basic_progress ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'progress';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_progress', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_progress;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_progress') drop index ix_migtest_e_basic_progress ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_progress', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_progress;
|
||||
alter table migtest_e_basic drop column progress;
|
||||
|
||||
-- drop column migtest_e_basic.new_integer;
|
||||
IF (OBJECT_ID('uq_migtest_e_basic_new_integer', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_integer;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_integer') drop index uq_migtest_e_basic_new_integer ON migtest_e_basic;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_integer';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_basic_new_integer', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_integer;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_integer') drop index ix_migtest_e_basic_new_integer ON migtest_e_basic;
|
||||
IF OBJECT_ID('fk_migtest_e_basic_new_integer', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_integer;
|
||||
alter table migtest_e_basic drop column new_integer;
|
||||
|
||||
-- drop column migtest_e_history2.test_string2;
|
||||
IF (OBJECT_ID('uq_migtest_e_history2_test_string2', 'UQ') IS NOT NULL) alter table migtest_e_history2 drop constraint uq_migtest_e_history2_test_string2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'uq_migtest_e_history2_test_string2') drop index uq_migtest_e_history2_test_string2 ON migtest_e_history2;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string2';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_history2_test_string2', 'C') IS NOT NULL) alter table migtest_e_history2 drop constraint ck_migtest_e_history2_test_string2;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'ix_migtest_e_history2_test_string2') drop index ix_migtest_e_history2_test_string2 ON migtest_e_history2;
|
||||
IF OBJECT_ID('fk_migtest_e_history2_test_string2', 'F') IS NOT NULL alter table migtest_e_history2 drop constraint fk_migtest_e_history2_test_string2;
|
||||
alter table migtest_e_history2 drop column test_string2;
|
||||
|
||||
-- drop column migtest_e_history2.test_string3;
|
||||
IF (OBJECT_ID('uq_migtest_e_history2_test_string3', 'UQ') IS NOT NULL) alter table migtest_e_history2 drop constraint uq_migtest_e_history2_test_string3;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'uq_migtest_e_history2_test_string3') drop index uq_migtest_e_history2_test_string3 ON migtest_e_history2;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string3';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_history2_test_string3', 'C') IS NOT NULL) alter table migtest_e_history2 drop constraint ck_migtest_e_history2_test_string3;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'ix_migtest_e_history2_test_string3') drop index ix_migtest_e_history2_test_string3 ON migtest_e_history2;
|
||||
IF OBJECT_ID('fk_migtest_e_history2_test_string3', 'F') IS NOT NULL alter table migtest_e_history2 drop constraint fk_migtest_e_history2_test_string3;
|
||||
alter table migtest_e_history2 drop column test_string3;
|
||||
|
||||
-- drop column migtest_e_softdelete.deleted;
|
||||
IF (OBJECT_ID('uq_migtest_e_softdelete_deleted', 'UQ') IS NOT NULL) alter table migtest_e_softdelete drop constraint uq_migtest_e_softdelete_deleted;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_softdelete','U') AND name = 'uq_migtest_e_softdelete_deleted') drop index uq_migtest_e_softdelete_deleted ON migtest_e_softdelete;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_softdelete') and t2.name = 'deleted';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_softdelete drop constraint ' + @Tmp)$$;
|
||||
IF (OBJECT_ID('ck_migtest_e_softdelete_deleted', 'C') IS NOT NULL) alter table migtest_e_softdelete drop constraint ck_migtest_e_softdelete_deleted;
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_softdelete','U') AND name = 'ix_migtest_e_softdelete_deleted') drop index ix_migtest_e_softdelete_deleted ON migtest_e_softdelete;
|
||||
IF OBJECT_ID('fk_migtest_e_softdelete_deleted', 'F') IS NOT NULL alter table migtest_e_softdelete drop constraint fk_migtest_e_softdelete_deleted;
|
||||
alter table migtest_e_softdelete drop column deleted;
|
||||
|
||||
IF OBJECT_ID('migtest_e_user', 'U') IS NOT NULL drop table migtest_e_user;
|
||||
-- dropping history support for migtest_e_history;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_history') and t2.name = 'sys_periodFrom';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_history drop constraint ' + @Tmp)$$;
|
||||
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
|
||||
where t1.parent_object_id = OBJECT_ID('migtest_e_history') and t2.name = 'sys_periodTo';
|
||||
if @Tmp is not null EXEC('alter table migtest_e_history drop constraint ' + @Tmp)$$;
|
||||
alter table migtest_e_history set (system_versioning = off);
|
||||
alter table migtest_e_history drop period for system_time;
|
||||
alter table migtest_e_history drop column sys_periodFrom;
|
||||
alter table migtest_e_history drop column sys_periodTo;
|
||||
IF OBJECT_ID('migtest_e_history_history', 'U') IS NOT NULL drop table migtest_e_history_history;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user