Extensions

We may want to use extensions like hstore and pgcrypto. Note that when using ebean-test with docker it will automatically add those 2 extensions by default.

We can specify extensions that should be installed automatically via:

ebean:
  test:
    platform: postgres #, h2, postgres, mysql, oracle, sqlserver
    ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
    dbName: myapp
    postgres:
      extensions: pgcrypto, hstore

In terms of logging / debugged we can see the extensions added via:

17:07:17.078 DEBUG io.ebean.docker.commands.Commands - create database extensions pgcrypto,hstore
17:07:17.078 DEBUG io.ebean.docker.commands.Commands - docker exec -i ut_postgres psql -U postgres -d test -c create extension if not exists pgcrypto
17:07:17.187 DEBUG io.ebean.docker.commands.Commands - docker exec -i ut_postgres psql -U postgres -d test -c create extension if not exists hstore

Schema

With Postgres it could be considered good practice to create our tables into a named schema (and not the public schema). If we want to do this we have made this easy in Ebean version 11.18.2 where we can specify ebean.dbSchema and this is then used for both DB migrations and create-all.sql.

It is advisable that the DB User matches the DB Schema. When this is done then there is no need to use currentSchema or modify the search path. For example, if I want to use a schema called myapp it is advisable to have the DB user/role match and be myapp.

application.yaml
ebean:
  dbSchema: myapp  ## use this schema for migrations and testing
ServerConfig
serverConfig.setDbSchema("myapp");

Postgis

Below is a test setup using the mdillon/postgis docker container that has PostGIS extension installed.

This will automatically download and run the container making live a little easier. Note the use of the Postgis specfic driver and url.

ebean:
  geometrySRID: 4674  # If we don't want the default geometrySRID of 4326

  test:
    shutdown: none # stop | remove | none
    platform: postgis
    ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
    dbName: mygisapp

The above postgis platform is equivalent to the setup below which uses:

  • Port 7432 by default (so as not to clash with local or non-gis postgres)
  • The org.postgis.DriverWrapperLW driver for binary encoded Geometry types
  • URL postgresql_lwgis in the connection url to use the LW driver
  • Uses mdillon/postgis docker image with Postgis installed
ebean:
  geometrySRID: 4674

  test:
    shutdown: none # stop | remove | none
    platform: postgres
    ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
    dbName: mygisapp
    postgres:
      containerName: postgis
      image: mdillon/postgis
      extensions: postgis
      url: jdbc:postgresql_lwgis://127.0.0.1:7432/mygisapp
      driver: org.postgis.DriverWrapperLW