mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +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
+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;
|
||||
}
|
||||
Reference in New Issue
Block a user