Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (76 sloc) 2.65 KB
<html>
<head>
<title>Postgres | Ebean ORM</title>
<meta name="layout" content="_layout/docs_database.html"/>
<meta name="bread2" content="Postgres" href="/docs/database/postgres"/>
<template id="menuNav"><#include "/_layout/_docs_nav_database_postgres.ftl"></template>
<#assign postgres="active">
</head>
<body>
<h2>Postgres</h2>
<h3>Testing</h3>
<p>
To test against Postgres docker test container set the <em>platform</em> to <code>postgres</code> in
<code>src/test/resources/application-test.yaml</code>
</p>
<p>
Refer to <a href="/docs/testing">docs / testing</a> if application-test.yaml doesn't exist yet.
</p>
```yml
ebean:
test:
platform: postgres # h2, postgres, ...
ddlMode: dropCreate # none | dropCreate | migration
dbName: my_app
```
<p>
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.
</p>
<p>
We generally run with <em>ddlMode</em> <code>dropCreate</code> which will drop and re-create
all the database tables prior to running all the tests.
</p>
<p>
Refer to <a href="/docs/logging">docs / logging</a> to see how to get logging for SQL, DDL and docker.
</p>
<p>
Note that DDL is generated into <em>maven target</em>, <em>gradle build</em> or current directory.
We see <code>db-create-all.sql</code> and <code>db-drop-all.sql</code> there.
</p>
<h3>Types</h3>
<h5>UUID</h5>
<p>
UUID is mapped to native Postgres UUID type.
</p>
<h5>INET</h5>
<p>
<em>java.net.InetAddress</em> and <em>io.ebean.types.Inet</em> 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. <em>io.ebean.types.Inet</em> is a simple value type.
</p>
<h5>Array types</h5>
<p>
We use <code><a href="arraytype">@DbArray</a></code> to map Lists or Sets of UUID, String, Enums, Number types.
These are mapped to Postgres array types like <em>uuid[], varchar[], integer[] ...</em>
</p>
<p>
For more on <a href="arraytype">Postgres Array types</a>.
</p>
<h5>JSON / JSONB</h5>
<p>
We can use <code>@DbJson</code> and <code>@DbJsonB</code> to map content to Postgres JSON or JSONB
types.
</p>
<h3>History support</h3>
<p>
History support for Postgres is provided by generating triggers and history table.
</p>
<h3>Table Partitioning</h3>
<p>
Postgres 10 added support for table partitioning. We use <code>@DbPartition</code> to define the
table should have range partitioning based on DAY, WEEK, MONTH or YEAR.
</p>
<@next_edit "Testing" "/docs/testing" "/docs/database/postgres/index.html"/>
</body>
</html>
You can’t perform that action at this time.