MariaDB
Since 12.3.6 MariaDB has it's own platform with SQL2012 History support and DDL generation to support that.
MariaDB JDBC Driver - useLegacyDatetimeCode
The expectation is that the MariaDB JDBC driver is used and that useLegacyDatetimeCode=false
is set. This ensures the JDBC driver honours the database server timezone. ebean-test will automatically
set the useLegacyDatetimeCode parameter for but otherwise we need to ensure that parameter is set on
the connection pool.
## example manually setting useLegacyDatetimeCode in properties file
datasource.db.username=my_app
datasource.db.password=test
datasource.db.url=jdbc:mariadb://localhost:4306/unit?useLegacyDatetimeCode=false
It is expected that the MariaDB JDBC Driver is used.
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.6.0</version>
</dependency>
Testing
To test against MariaDB docker test container set the platform to mariadb
in
src/test/resources/application-test.yaml
Refer to docs / testing if application-test.yaml doesn't exist yet.
ebean:
test:
platform: mariadb
ddlMode: dropCreate # none | dropCreate | migrations | create
dbName: my_app
The above will use the following defaults:
username: | {dbName} |
---|---|
password: | test |
port: | 4306 |
url: | jdbc:mariadb://localhost:{port}/{dbName}?useLegacyDatetimeCode=false |
image: | mariadb:{version:10} |
Types
UUID
UUID is not a native MariaDB type and can be mapped to either BINARY(16) or VARCHAR(36).
JSON
We can use @DbJson
to map content.
History support
MariaDB has native SQL2011 history support and Ebean will generate DDL to enable and use this
on entities annotated with @History
.
Programmatically start using docker
We can programmatically start a MariaDB docker container using ebean-test-docker
via:
package main;
import io.ebean.docker.commands.MariaDBConfig;
import io.ebean.docker.commands.MariaDBContainer;
public class StartMariaDb {
public static void main(String[] args) {
MariaDBConfig config = new MariaDBConfig("10.5");
config.setDbName("unit");
config.setUser("unit");
config.setPassword("unit");
MariaDBContainer container = new MariaDBContainer(config);
container.startWithDropCreate();
}
}