mapping = new HashMap<>();
+ static {
+ mapping.put("uuid[]", "Array(UUID)");
+ mapping.put("varchar[]", "Array(String)");
+ mapping.put("integer[]", "Array(UInt32)");
+ mapping.put("bigint[]", "Array(UInt64)");
+ }
+
+ /**
+ * Covert the 'logical' array type to a native one (for Postgres and Cockroach).
+ */
+ static String logicalToNative(String logicalArrayType) {
+ int colonPos = logicalArrayType.indexOf(':');
+ if (colonPos > -1) {
+ logicalArrayType = logicalArrayType.substring(0, colonPos);
+ }
+ String clickHouseType = mapping.get(logicalArrayType);
+ if (clickHouseType == null) {
+ throw new IllegalStateException("No mapping for logical array type " + logicalArrayType);
+ }
+ return clickHouseType;
+ }
+}
diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdl.java
new file mode 100644
index 000000000..0c680f3eb
--- /dev/null
+++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdl.java
@@ -0,0 +1,86 @@
+package io.ebeaninternal.dbmigration.ddlgeneration.platform;
+
+import io.ebean.config.ServerConfig;
+import io.ebean.config.dbplatform.DatabasePlatform;
+import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
+import io.ebeaninternal.dbmigration.ddlgeneration.DdlHandler;
+
+import java.io.IOException;
+
+public class ClickHouseDdl extends PlatformDdl {
+
+ private static final String LOG_TABLE = "ENGINE = Log()";
+
+ public ClickHouseDdl(DatabasePlatform platform) {
+ super(platform);
+ this.includeStorageEngine = true;
+ this.identitySuffix = "";
+ }
+
+ @Override
+ public DdlHandler createDdlHandler(ServerConfig serverConfig) {
+ return new ClickHouseDdlHandler(serverConfig, this);
+ }
+
+ @Override
+ protected String convertArrayType(String logicalArrayType) {
+ return ClickHouseDbArray.logicalToNative(logicalArrayType);
+ }
+
+ /**
+ * Add an table storage engine to the create table statement.
+ */
+ @Override
+ public void tableStorageEngine(DdlBuffer apply, String storageEngine) throws IOException {
+ if (storageEngine == null) {
+ // default to Log() table but really should all be explicit (need arguments for MergeTree etc)
+ storageEngine = LOG_TABLE;
+ }
+ apply.append(" ").append(storageEngine);
+ }
+
+ @Override
+ public String alterTableAddForeignKey(WriteForeignKey request) {
+ return null;
+ }
+
+ @Override
+ public String alterTableDropForeignKey(String tableName, String fkName) {
+ return null;
+ }
+
+ @Override
+ public String tableInlineForeignKey(WriteForeignKey request) {
+ return null;
+ }
+
+ @Override
+ public String dropIndex(String indexName, String tableName) {
+ return null;
+ }
+
+ @Override
+ public String createIndex(String indexName, String tableName, String[] columns) {
+ return null;
+ }
+
+ @Override
+ protected void writeColumnNotNull(DdlBuffer buffer) {
+ // do nothing
+ }
+
+ @Override
+ public void addTableComment(DdlBuffer apply, String tableName, String tableComment) {
+ // do nothing
+ }
+
+ @Override
+ public void addColumnComment(DdlBuffer apply, String table, String column, String comment) {
+ // do nothing
+ }
+
+ @Override
+ public boolean isInlineComments() {
+ return false;
+ }
+}
diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdlHandler.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdlHandler.java
new file mode 100644
index 000000000..2371cfaee
--- /dev/null
+++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDdlHandler.java
@@ -0,0 +1,11 @@
+package io.ebeaninternal.dbmigration.ddlgeneration.platform;
+
+import io.ebean.config.ServerConfig;
+import io.ebeaninternal.dbmigration.ddlgeneration.BaseDdlHandler;
+
+public class ClickHouseDdlHandler extends BaseDdlHandler {
+
+ public ClickHouseDdlHandler(ServerConfig serverConfig, PlatformDdl platformDdl) {
+ super(serverConfig, platformDdl, new ClickHouseTableDdl(serverConfig, platformDdl));
+ }
+}
diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseTableDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseTableDdl.java
new file mode 100644
index 000000000..b959d1ff7
--- /dev/null
+++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseTableDdl.java
@@ -0,0 +1,34 @@
+package io.ebeaninternal.dbmigration.ddlgeneration.platform;
+
+import io.ebean.config.ServerConfig;
+import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
+import io.ebeaninternal.dbmigration.migration.CreateTable;
+
+public class ClickHouseTableDdl extends BaseTableDdl {
+
+ public ClickHouseTableDdl(ServerConfig serverConfig, PlatformDdl platformDdl) {
+ super(serverConfig, platformDdl);
+ }
+
+ @Override
+ protected void writePrimaryKeyConstraint(DdlBuffer buffer, String pkName, String[] pkColumns) {
+ // do nothing
+ }
+
+ @Override
+ protected void writeCompoundUniqueConstraints(DdlBuffer apply, CreateTable createTable) {
+ // do nothing
+ }
+
+ @Override
+ protected void writeUniqueConstraints(DdlBuffer apply, CreateTable createTable) {
+ // do nothing
+ }
+
+
+ @Override
+ protected void writeCheckConstraints(DdlBuffer apply, CreateTable createTable) {
+ // do nothing
+ }
+
+}
diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java
index 4159bfb3d..eb69d3be3 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java
@@ -104,7 +104,6 @@ public class MySqlDdl extends PlatformDdl {
}
buffer.append(String.format(" comment '%s'", comment));
}
-
}
@Override
diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
index f6a65da81..d76c6bd44 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java
@@ -118,6 +118,8 @@ public class PlatformDdl {
*/
protected boolean inlineForeignKeys;
+ protected boolean includeStorageEngine;
+
protected final DbDefaultValue dbDefaultValue;
protected String fallbackArrayType = "varchar(1000)";
@@ -191,6 +193,13 @@ public class PlatformDdl {
return inlineComments;
}
+ /**
+ * Return true if the platform includes storage engine clause.
+ */
+ public boolean isIncludeStorageEngine() {
+ return includeStorageEngine;
+ }
+
/**
* Return true if foreign key reference constraints need to inlined with create table.
* Ideally we don't do this as then the constraints are not named. Do this for SQLite.
@@ -230,13 +239,20 @@ public class PlatformDdl {
}
}
if (isTrue(column.isNotnull()) || isTrue(column.isPrimaryKey())) {
- buffer.append(" not null");
+ writeColumnNotNull(buffer);
}
// add check constraints later as we really want to give them a nice name
// so that the database can potentially provide a nice SQL error
}
+ /**
+ * Allow for platform overriding (e.g. ClickHouse).
+ */
+ protected void writeColumnNotNull(DdlBuffer buffer) throws IOException {
+ buffer.append(" not null");
+ }
+
/**
* Convert the DB column default literal to platform specific.
*/
@@ -409,13 +425,17 @@ public class PlatformDdl {
}
protected String translate(ConstraintMode mode) {
- switch(mode) {
- case SET_NULL: return "set null";
- case SET_DEFAULT: return "set default";
- case RESTRICT: return "restrict";
- case CASCADE: return "cascade";
+ switch (mode) {
+ case SET_NULL:
+ return "set null";
+ case SET_DEFAULT:
+ return "set default";
+ case RESTRICT:
+ return "restrict";
+ case CASCADE:
+ return "cascade";
default:
- throw new IllegalStateException("Unknown mode "+mode);
+ throw new IllegalStateException("Unknown mode " + mode);
}
}
@@ -465,7 +485,7 @@ public class PlatformDdl {
if (!onHistoryTable) {
if (isTrue(column.isNotnull())) {
- buffer.append(" not null");
+ writeColumnNotNull(buffer);
}
buffer.append(addColumnSuffix);
buffer.endOfStatement();
@@ -473,7 +493,7 @@ public class PlatformDdl {
// check constraints cannot be added in one statement for h2
if (!StringHelper.isNull(column.getCheckConstraint())) {
String ddl = alterTableAddCheckConstraint(tableName, column.getCheckConstraintName(),
- column.getCheckConstraint());
+ column.getCheckConstraint());
buffer.append(ddl).endOfStatement();
}
} else {
@@ -485,7 +505,7 @@ public class PlatformDdl {
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
buffer.append("alter table ").append(tableName).append(" ").append(dropColumn).append(" ").append(columnName)
- .append(dropColumnSuffix).endOfStatement();
+ .append(dropColumnSuffix).endOfStatement();
}
/**
@@ -607,6 +627,13 @@ public class PlatformDdl {
// do nothing by default (MySql only)
}
+ /**
+ * Add an table storage engine to the create table statement.
+ */
+ public void tableStorageEngine(DdlBuffer apply, String storageEngine) throws IOException {
+ // do nothing by default
+ }
+
/**
* Add table comment as a separate statement (from the create table statement).
*/
@@ -643,10 +670,10 @@ public class PlatformDdl {
/**
* Shortens the given name to the maximum constraint name length of the platform in a deterministic way.
- *
+ *
* First, all vowels are removed, If the string is still to long, 31 bits are taken from the hash code
* of the string and base36 encoded (10 digits and 26 chars) string.
- *
+ *
* As 36^6 > 31^2, the resulting string is never longer as 6 chars.
*/
protected String maxConstraintName(String name) {
@@ -654,7 +681,7 @@ public class PlatformDdl {
int hash = name.hashCode() & 0x7FFFFFFF;
name = VowelRemover.trim(name, 4);
if (name.length() > platform.getMaxConstraintNameLength()) {
- return name.substring(0, platform.getMaxConstraintNameLength()-7) + "_" + Integer.toString(hash, 36);
+ return name.substring(0, platform.getMaxConstraintNameLength() - 7) + "_" + Integer.toString(hash, 36);
}
}
return name;
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
index cf27b1ce0..c088ffc09 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
@@ -77,6 +77,8 @@ public class CreateTable {
protected BigInteger sequenceAllocate;
@XmlAttribute(name = "pkName")
protected String pkName;
+ @XmlAttribute(name = "storageEngine")
+ protected String storageEngine;
@XmlAttribute(name = "tablespace")
protected String tablespace;
@XmlAttribute(name = "indexTablespace")
@@ -365,6 +367,26 @@ public class CreateTable {
this.pkName = value;
}
+ /**
+ * Gets the value of the storageEngine property.
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ public String getStorageEngine() {
+ return storageEngine;
+ }
+
+ /**
+ * Sets the value of the storageEngine property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setStorageEngine(String value) {
+ this.storageEngine = value;
+ }
+
/**
* Gets the value of the tablespace property.
*
diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java b/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java
index b3f783a0b..e37ca0377 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java
@@ -67,14 +67,14 @@ public class CurrentModel {
* Return true if the model contains tables that are partitioned.
*/
public boolean isTablePartitioning() {
- return model.isTablePartitioning();
+ return read().isTablePartitioning();
}
/**
* Return the tables that have partitioning.
*/
public List getPartitionedTables() {
- return model.getPartitionedTables();
+ return read().getPartitionedTables();
}
private static DbConstraintNaming.MaxLength maxLength(SpiEbeanServer server, DbConstraintNaming naming) {
diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
index 2a6b0a8b3..c80281472 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java
@@ -79,6 +79,8 @@ public class MTable {
*/
private String tablespace;
+ private String storageEngine;
+
/**
* Tablespace to use for indexes on this table.
*/
@@ -159,6 +161,7 @@ public class MTable {
this.name = createTable.getName();
this.pkName = createTable.getPkName();
this.comment = createTable.getComment();
+ this.storageEngine = createTable.getStorageEngine();
this.tablespace = createTable.getTablespace();
this.indexTablespace = createTable.getIndexTablespace();
this.withHistory = Boolean.TRUE.equals(createTable.isWithHistory());
@@ -244,6 +247,7 @@ public class MTable {
createTable.setPartitionMode(partitionMeta.getMode().name());
createTable.setPartitionColumn(partitionMeta.getProperty());
}
+ createTable.setStorageEngine(storageEngine);
createTable.setTablespace(tablespace);
createTable.setIndexTablespace(indexTablespace);
createTable.setSequenceName(sequenceName);
@@ -452,6 +456,10 @@ public class MTable {
this.comment = comment;
}
+ public void setStorageEngine(String storageEngine) {
+ this.storageEngine = storageEngine;
+ }
+
public String getTablespace() {
return tablespace;
}
diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java
index 8ac300074..9b6e3147e 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java
@@ -36,6 +36,7 @@ public class ModelBuildBeanVisitor implements BeanVisitor {
}
MTable table = new MTable(descriptor.getBaseTable());
+ table.setStorageEngine(descriptor.getStorageEngine());
table.setPartitionMeta(descriptor.getPartitionMeta());
table.setComment(descriptor.getDbComment());
if (descriptor.isHistorySupport()) {
diff --git a/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java b/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java
index b5a5b6ef5..9cd221c92 100644
--- a/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java
+++ b/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.core;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
+import io.ebean.config.dbplatform.clickhouse.ClickHousePlatform;
import io.ebean.config.dbplatform.cockroach.CockroachPlatform;
import io.ebean.config.dbplatform.db2.DB2Platform;
import io.ebean.config.dbplatform.h2.H2Platform;
@@ -104,6 +105,9 @@ public class DatabasePlatformFactory {
if (dbName.equals("db2")) {
return new DB2Platform();
}
+ if (dbName.equals("clickhouse")) {
+ return new ClickHousePlatform();
+ }
if (dbName.equals("sqlite")) {
return new SQLitePlatform();
}
@@ -162,6 +166,8 @@ public class DatabasePlatformFactory {
return new SqlAnywherePlatform();
} else if (dbProductName.contains("hdb")) {
return new HanaPlatform();
+ } else if (dbProductName.contains("clickhouse")) {
+ return new ClickHousePlatform();
}
// use the standard one
diff --git a/src/main/java/io/ebeaninternal/server/core/PlatformDdlBuilder.java b/src/main/java/io/ebeaninternal/server/core/PlatformDdlBuilder.java
index dbf657c49..34e696735 100644
--- a/src/main/java/io/ebeaninternal/server/core/PlatformDdlBuilder.java
+++ b/src/main/java/io/ebeaninternal/server/core/PlatformDdlBuilder.java
@@ -1,6 +1,7 @@
package io.ebeaninternal.server.core;
import io.ebean.config.dbplatform.DatabasePlatform;
+import io.ebeaninternal.dbmigration.ddlgeneration.platform.ClickHouseDdl;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.CockroachDdl;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DB2Ddl;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.H2Ddl;
@@ -50,6 +51,8 @@ public class PlatformDdlBuilder {
return new SqlServerDdl(platform);
case HANA:
return new HanaColumnStoreDdl(platform);
+ case CLICKHOUSE:
+ return new ClickHouseDdl(platform);
default:
return new PlatformDdl(platform);
}
diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java
index 8add0f49a..7d3cba9c1 100644
--- a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java
+++ b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java
@@ -211,6 +211,7 @@ public class BeanDescriptor implements BeanType, STreeType {
private final String draftTable;
private final PartitionMeta partitionMeta;
+ private final String storageEngine;
/**
* DB table comment.
@@ -492,6 +493,7 @@ public class BeanDescriptor implements BeanType, STreeType {
this.dependentTables = deploy.getDependentTables();
this.dbComment = deploy.getDbComment();
this.partitionMeta = deploy.getPartitionMeta();
+ this.storageEngine = deploy.getStorageEngine();
this.autoTunable = EntityType.ORM == entityType && (beanFinder == null);
// helper object used to derive lists of properties
@@ -1970,10 +1972,10 @@ public class BeanDescriptor implements BeanType, STreeType {
DefaultOrmQuery query = new DefaultOrmQuery<>(this, ebeanServer, ebeanServer.getExpressionFactory());
query.setPersistenceContext(pc);
return query
- // .select(getIdProperty().getName())
- // we do not select the id because we
- // probably have to load the entire bean
- .setId(id).findOne();
+ // .select(getIdProperty().getName())
+ // we do not select the id because we
+ // probably have to load the entire bean
+ .setId(id).findOne();
}
/**
@@ -2874,6 +2876,13 @@ public class BeanDescriptor implements BeanType, STreeType {
return partitionMeta;
}
+ /**
+ * Return the storage engine.
+ */
+ public String getStorageEngine() {
+ return storageEngine;
+ }
+
/**
* Return the dependent tables for a view based entity.
*
diff --git a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java
index 18873232a..b43b0d6fc 100644
--- a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java
+++ b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java
@@ -136,6 +136,8 @@ public class DeployBeanDescriptor {
private List indexDefinitions;
+ private String storageEngine;
+
/**
* The base database table.
*/
@@ -275,6 +277,14 @@ public class DeployBeanDescriptor {
return Modifier.isAbstract(beanType.getModifiers());
}
+ public void setStorageEngine(String storageEngine) {
+ this.storageEngine = storageEngine;
+ }
+
+ public String getStorageEngine() {
+ return storageEngine;
+ }
+
/**
* Set to true for @History entity beans that have history.
*/
@@ -315,7 +325,7 @@ public class DeployBeanDescriptor {
this.partitionMeta = partitionMeta;
}
- public PartitionMeta getPartitionMeta() {
+ public PartitionMeta getPartitionMeta() {
if (partitionMeta != null) {
DeployBeanProperty beanProperty = getBeanProperty(partitionMeta.getProperty());
if (beanProperty != null) {
diff --git a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java
index 083d04b61..657c94797 100644
--- a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java
+++ b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java
@@ -10,6 +10,7 @@ import io.ebean.annotation.History;
import io.ebean.annotation.Index;
import io.ebean.annotation.InvalidateQueryCache;
import io.ebean.annotation.ReadAudit;
+import io.ebean.annotation.StorageEngine;
import io.ebean.annotation.UpdateMode;
import io.ebean.annotation.View;
import io.ebean.config.TableName;
@@ -154,6 +155,11 @@ public class AnnotationClass extends AnnotationParser {
}
}
+ StorageEngine storage = AnnotationUtil.findAnnotationRecursive(cls, StorageEngine.class);
+ if (storage != null) {
+ descriptor.setStorageEngine(storage.value());
+ }
+
DbPartition partition = AnnotationUtil.findAnnotationRecursive(cls, DbPartition.class);
if (partition != null) {
descriptor.setPartitionMeta(new PartitionMeta(partition.mode(), partition.property()));
diff --git a/src/main/resources/ebean-dbmigration-1.0.xsd b/src/main/resources/ebean-dbmigration-1.0.xsd
index a78d2fade..3066f38b1 100644
--- a/src/main/resources/ebean-dbmigration-1.0.xsd
+++ b/src/main/resources/ebean-dbmigration-1.0.xsd
@@ -116,6 +116,7 @@
+
diff --git a/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdlTest.java b/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdlTest.java
index d36abb449..b141cd979 100644
--- a/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdlTest.java
+++ b/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdlTest.java
@@ -2,6 +2,7 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.ServerConfig;
+import io.ebean.config.dbplatform.clickhouse.ClickHousePlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
@@ -62,6 +63,23 @@ public class BaseTableDdlTest {
assertThat(ddl).contains("alter table mytable add column col_name varchar2(20)");
}
+ @Test
+ public void testAddColumn_withTypeConversion_clickHouseVarchar() throws IOException {
+
+ ClickHouseTableDdl ddlGen = new ClickHouseTableDdl(serverConfig, PlatformDdlBuilder.create(new ClickHousePlatform()));
+
+ DdlWrite write = new DdlWrite();
+
+ Column column = new Column();
+ column.setName("col_name");
+ column.setType("varchar(20)");
+
+ ddlGen.alterTableAddColumn(write.apply(), "mytable", column, false, false);
+
+ String ddl = write.apply().getBuffer();
+ assertThat(ddl).contains("alter table mytable add column col_name String");
+ }
+
@Test
public void testAlterColumnComment() throws IOException {
diff --git a/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDbArrayTest.java b/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDbArrayTest.java
new file mode 100644
index 000000000..181630396
--- /dev/null
+++ b/src/test/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/ClickHouseDbArrayTest.java
@@ -0,0 +1,24 @@
+package io.ebeaninternal.dbmigration.ddlgeneration.platform;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ClickHouseDbArrayTest {
+
+ @Test
+ public void logicalToNative() {
+
+ assertThat(ClickHouseDbArray.logicalToNative("uuid[]")).isEqualTo("Array(UUID)");
+ assertThat(ClickHouseDbArray.logicalToNative("varchar[]")).isEqualTo("Array(String)");
+ assertThat(ClickHouseDbArray.logicalToNative("integer[]")).isEqualTo("Array(UInt32)");
+ assertThat(ClickHouseDbArray.logicalToNative("bigint[]")).isEqualTo("Array(UInt64)");
+ }
+
+ @Test
+ public void logicalToNative_withFallbackDefined() {
+
+ assertThat(ClickHouseDbArray.logicalToNative("uuid[]:(1000)")).isEqualTo("Array(UUID)");
+ }
+
+}