Skip to content

Commit

Permalink
#2743 - Postgres DDL - For create table, improve column ordering for …
Browse files Browse the repository at this point in the history
…tighter storage
  • Loading branch information
rbygrave committed Jul 7, 2022
1 parent 110bc61 commit 5f6efd2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public String setLockTimeout(int lockTimeoutSeconds) {
* 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(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private boolean isLob(String type) {
}

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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class PostgresDdlTest {

private PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());
final PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());

@Test
void setLockTimeout() {
Expand Down Expand Up @@ -40,6 +40,12 @@ void sortColumns_varbinary() {
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)"));
Expand Down

0 comments on commit 5f6efd2

Please sign in to comment.