mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2743 - Postgres DDL - For create table, improve column ordering for tighter storage
This commit is contained in:
+3
-1
@@ -198,7 +198,9 @@ public class PlatformDdl {
|
||||
* Write all the table columns converting to platform types as necessary.
|
||||
*/
|
||||
public void writeTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity) {
|
||||
columns = sortColumns(columns);
|
||||
if ("true".equalsIgnoreCase(System.getProperty("ebean.ddl.sortColumns", "true"))) {
|
||||
columns = sortColumns(columns);
|
||||
}
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
if (i > 0) {
|
||||
apply.append(",");
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class PostgresDdl extends PlatformDdl {
|
||||
}
|
||||
|
||||
private boolean isVariableLength(String type) {
|
||||
return type.startsWith("varchar") || type.startsWith("varbinary");
|
||||
return type.startsWith("varchar") || type.startsWith("varbinary") || type.startsWith("json");
|
||||
}
|
||||
|
||||
static final class DDLColumnSort implements Comparable<DDLColumnSort> {
|
||||
|
||||
+7
-1
@@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class PostgresDdlTest {
|
||||
|
||||
private PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());
|
||||
final PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());
|
||||
|
||||
@Test
|
||||
void setLockTimeout() {
|
||||
@@ -40,6 +40,12 @@ class PostgresDdlTest {
|
||||
assertThat(cols).extracting("type").containsExactly("int", "decimal(1)", "decimal(2)", "varbinary(1)", "varbinary(2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sortColumns_json() {
|
||||
List<Column> cols = postgresDdl.sortColumns(columns("json", "jsonb", "int"));
|
||||
assertThat(cols).extracting("type").containsExactly("int", "json", "jsonb");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sortColumns_clobs() {
|
||||
List<Column> cols = postgresDdl.sortColumns(columns("clob", "blob", "longvarchar(1)", "int", "longvarbinary(2)"));
|
||||
|
||||
Reference in New Issue
Block a user