For some reason there's no documentation on running liquibase inside Java code. I want to generate tables for Unit tests.
How would I run it directly in Java?
e.g.
Liquibase liquibase = new Liquibase()
liquibase.runUpdates() ?
For some reason there's no documentation on running liquibase inside Java code. I want to generate tables for Unit tests.
How would I run it directly in Java?
e.g.
Liquibase liquibase = new Liquibase()
liquibase.runUpdates() ?
I found a way to achieve setting up the database using either maven or Java. The above example uses
FileSystemResourceAccessor()
, which unfortunately makes it so that if you deploy an application which needs to set up a database from the jar itself, then you end up having to extract the jar as a zip as a workaround, since these liquibase files exist only in the jar. This means your jar ultimately isn't portable, and you have to havemaven
wherever you want to set up the database.Use this structure:
src/main/resources/liquibase/db.changelog-master.xml
src/main/resources/liquibase/changelogs/...
Your DB changelog master can look like this:
You can use this section for your pom.xml, in order to make sure
mvn install
will also set up your liquibase DB.Use
ClassLoaderResourceAccessor()
instead ofFileSystemResourceAccessor()
.It should be something like (taken from liquibase.integration.spring.SpringLiquibase source):
There are multiple implementation of ResourceAccessor depending on how your changelog files should be found.