#1147 - Refactor move DbMigration internals into io.ebeaninternal - change to use DbMigration.create() - move PlatformDdl into internal

This commit is contained in:
rob bygrave
2017-10-04 20:30:57 +13:00
parent c6fc7a032d
commit 62707caf64
24 changed files with 122 additions and 90 deletions
@@ -2,17 +2,18 @@ package io.ebean.config.dbplatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class H2PlatformTest {
H2Platform mySqlPlatform = new H2Platform();
@Test
public void testTypeConversion() {
PlatformDdl ddl = mySqlPlatform.getPlatformDdl();
PlatformDdl ddl = PlatformDdlBuilder.create(new H2Platform());
assertThat(ddl.convert("clob", false)).isEqualTo("clob");
assertThat(ddl.convert("json", false)).isEqualTo("clob");
assertThat(ddl.convert("jsonb", false)).isEqualTo("clob");
@@ -4,6 +4,7 @@ import io.ebean.config.DbTypeConfig;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -14,7 +15,7 @@ public class MySqlPlatformTest {
@Test
public void testTypeConversion() {
PlatformDdl ddl = mySqlPlatform.getPlatformDdl();
PlatformDdl ddl = PlatformDdlBuilder.create(mySqlPlatform);
assertThat(ddl.convert("clob", false)).isEqualTo("longtext");
assertThat(ddl.convert("json", false)).isEqualTo("longtext");
assertThat(ddl.convert("jsonb", false)).isEqualTo("longtext");
@@ -4,6 +4,7 @@ import io.ebean.config.DbTypeConfig;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -15,7 +16,7 @@ public class OraclePlatformTest {
@Test
public void testTypeConversion() {
PlatformDdl ddl = platform.getPlatformDdl();
PlatformDdl ddl = PlatformDdlBuilder.create(platform);
assertThat(ddl.convert("clob", false)).isEqualTo("clob");
assertThat(ddl.convert("blob", false)).isEqualTo("blob");
@@ -3,6 +3,7 @@ package io.ebean.config.dbplatform;
import io.ebean.config.DbTypeConfig;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -14,7 +15,7 @@ public class PostgresPlatformTest {
public void testTypeConversion() {
PostgresPlatform platform = new PostgresPlatform();
PlatformDdl ddl = platform.getPlatformDdl();
PlatformDdl ddl = PlatformDdlBuilder.create(platform);
assertThat(ddl.convert("clob", false)).isEqualTo("text");
assertThat(ddl.convert("blob", false)).isEqualTo("bytea");
@@ -15,6 +15,7 @@ import io.ebean.meta.MetaInfoManager;
import io.ebean.plugin.SpiServer;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlHandler;
import io.ebeaninternal.server.core.timezone.DataTimeZone;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.query.CQuery;
@@ -87,6 +88,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
return null;
}
@Override
public DdlHandler createDdlHandler() {
return null;
}
@Override
public CallStack createCallStack() {
return null;
@@ -3,12 +3,14 @@ package io.ebeaninternal.dbmigration.ddlgeneration;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.model.CurrentModel;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Ignore;
import org.junit.Test;
@@ -17,18 +19,22 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BaseDdlHandlerTest extends BaseTestCase {
ServerConfig serverConfig = new ServerConfig();
private ServerConfig serverConfig = new ServerConfig();
private DdlHandler handler(DatabasePlatform platform) {
return PlatformDdlBuilder.create(platform).createDdlHandler(serverConfig);
}
private DdlHandler h2Handler() {
return new H2Platform().createDdlHandler(serverConfig);
return handler(new H2Platform());
}
private DdlHandler postgresHandler() {
return new PostgresPlatform().createDdlHandler(serverConfig);
return handler(new PostgresPlatform());
}
private DdlHandler sqlserverHandler() {
return new SqlServerPlatform().createDdlHandler(serverConfig);
return handler(new SqlServerPlatform());
}
@Test
@@ -11,6 +11,7 @@ import io.ebeaninternal.dbmigration.migration.AddTableComment;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.Column;
import io.ebeaninternal.dbmigration.migration.CreateTable;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import java.io.IOException;
@@ -21,12 +22,14 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BaseTableDdlTest {
ServerConfig serverConfig = new ServerConfig();
private ServerConfig serverConfig = new ServerConfig();
private PlatformDdl h2ddl = PlatformDdlBuilder.create(new H2Platform());
@Test
public void testAlterColumn() throws IOException {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new H2Platform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, h2ddl);
DdlWrite write = new DdlWrite();
@@ -45,7 +48,7 @@ public class BaseTableDdlTest {
@Test
public void testAddColumn_withTypeConversion() throws IOException {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new OraclePlatform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, PlatformDdlBuilder.create(new OraclePlatform()));
DdlWrite write = new DdlWrite();
@@ -62,7 +65,7 @@ public class BaseTableDdlTest {
@Test
public void testAlterColumnComment() throws IOException {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new H2Platform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, h2ddl);
DdlWrite write = new DdlWrite();
@@ -80,7 +83,7 @@ public class BaseTableDdlTest {
@Test
public void testAddTableComment() throws IOException {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new H2Platform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, h2ddl);
DdlWrite write = new DdlWrite();
@@ -97,7 +100,7 @@ public class BaseTableDdlTest {
@Test
public void testAddTableComment_mysql() throws IOException {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new MySqlPlatform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, PlatformDdlBuilder.create(new MySqlPlatform()));
DdlWrite write = new DdlWrite();
@@ -114,7 +117,7 @@ public class BaseTableDdlTest {
@Test
public void testGenerate() throws Exception {
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, new H2Platform().getPlatformDdl());
BaseTableDdl ddlGen = new BaseTableDdl(serverConfig, h2ddl);
DdlWrite write = new DdlWrite();
@@ -7,6 +7,7 @@ import io.ebeaninternal.dbmigration.model.CurrentModel;
import io.ebeaninternal.dbmigration.model.MConfiguration;
import io.ebeaninternal.dbmigration.model.ModelContainer;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
@@ -29,7 +30,7 @@ public class H2HistoryDdlTest {
DdlWrite write = new DdlWrite(new MConfiguration(), modelContainer);
H2Platform h2Platform = new H2Platform();
PlatformDdl h2Ddl = h2Platform.getPlatformDdl();
PlatformDdl h2Ddl = PlatformDdlBuilder.create(h2Platform);
h2Ddl.configure(ebeanServer.getServerConfig());
h2Ddl.regenerateHistoryTriggers(write, update);
@@ -8,6 +8,7 @@ import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -16,11 +17,11 @@ import static org.junit.Assert.assertNull;
public class PlatformDdl_AlterColumnTest {
PlatformDdl h2Ddl = new H2Platform().getPlatformDdl();
PlatformDdl pgDdl = new PostgresPlatform().getPlatformDdl();
PlatformDdl mysqlDdl = new MySqlPlatform().getPlatformDdl();
PlatformDdl oraDdl = new OraclePlatform().getPlatformDdl();
PlatformDdl sqlServerDdl = new SqlServerPlatform().getPlatformDdl();
PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
{
ServerConfig serverConfig = Ebean.getDefaultServer().getPluginApi().getServerConfig();
@@ -5,6 +5,7 @@ import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -12,11 +13,11 @@ import static org.junit.Assert.assertEquals;
public class PlatformDdl_dropUniqueConstraintTest {
PlatformDdl h2Ddl = new H2Platform().getPlatformDdl();
PlatformDdl pgDdl = new PostgresPlatform().getPlatformDdl();
PlatformDdl mysqlDdl = new MySqlPlatform().getPlatformDdl();
PlatformDdl oraDdl = new OraclePlatform().getPlatformDdl();
PlatformDdl sqlServerDdl = new SqlServerPlatform().getPlatformDdl();
private PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
private PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
@Test
public void test() throws Exception {