Overview

Ebean can generate and execute CREATE ALL and DROP ALL DDL scripts which create all the tables. This is used for testing purposes.

When running a test or suite of tests the DB is created entirely from scratch

Using ebean-test-config

The best way to control and run DDL for testing is to use ebean-test-config and the ddlMode. Using dropCreate means the DDL for create-all and drop-all is generated and run.

In application-test.yml
ebean:
  test:
    platform: h2 # h2, postgres, mysql, oracle, sqlserver
    ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
    dbName: myapp

Using properties

If we don't want to use ebean-test-config we can instead set both ebean.ddl.generate and ebean.ddl.run properties to true in application-test.yml (which is in src/test/resources) and in this way the CREATE ALL DDL is only generated and executed when running tests.

In application-test.yml
ebean:
  ddl:
    generate: true
    run: true
Or application-test.properties
ebean.ddl.generate=true
ebean.ddl.run=true

Initial DDL

We can specify DDL to execute prior to running the `create-all` DDL.

ebean.ddl.initSql=testInitialDdl.sql

Seed DDL

We can specify DDL to execute after running the `create-all` DDL which we typically use to seed the database.

ebean.ddl.seedSql=testSeedData.sql

DB Migration

DB Migration is different in that DIFF DDL scripts are generated for the changes to the model and these DIFF DDL scripts can be applied to the target database typically at runtime.