Postgres

Testing

To test against Postgres docker test container set the platform to postgres in src/test/resources/application-test.yaml

Refer to docs / testing if application-test.yaml doesn't exist yet.

ebean:
  test:
  platform: postgres # h2, postgres, ...
    ddlMode: dropCreate # none | dropCreate | migration
    dbName: my_app

That is all we need to do. Running tests via IDE, maven or gradle will all automatically setup a docker test container for postgres including creating the database and user etc.

We generally run with ddlMode dropCreate which will drop and re-create all the database tables prior to running all the tests.

Refer to docs / logging to see how to get logging for SQL, DDL and docker.

Note that DDL is generated into maven target, gradle build or current directory. We see db-create-all.sql and db-drop-all.sql there.

Types

UUID

UUID is mapped to native Postgres UUID type.

INET

java.net.InetAddress and io.ebean.types.Inet are both automatically mapped to native Postgres INET type. When using InetAddress we need to take care that it doesn't perform unwanted DNS lookup validating addresses. io.ebean.types.Inet is a simple value type.

Array types

We use @DbArray to map Lists or Sets of UUID, String, Enums, Number types. These are mapped to Postgres array types like uuid[], varchar[], integer[] ...

For more on Postgres Array types.

JSON / JSONB

We can use @DbJson and @DbJsonB to map content to Postgres JSON or JSONB types.

History support

History support for Postgres is provided by generating triggers and history table.

Table Partitioning

Postgres 10 added support for table partitioning. We use @DbPartition to define the table should have range partitioning based on DAY, WEEK, MONTH or YEAR.

Edit Page