Search code examples
javamaven-2jakarta-eehbm2ddlliquibase

How do I mimic Hibernate hbm2ddl "create" behaviour in Liquibase?


I've worked with liquibase 1.9.5 for a while now and got it to replace hibernate hbm2ddl strategy of creating tables and loading fixtures in it. Since it's a maven project and since I use hsqldb (using file create=true), I simply create the db in the target folder so that I have a fresh database anytime I test the application. Works fine till that I realize:

1 I will need the database to be recreated when doing integration test using mysql database now

2 I will definitely need the same solution for a non maven project.

So basically how do I drop and create the database when using liquibase as opposed to hbm2ddl?


Solution

  • The easiest way is to add a separate database call before liquibase update that runs the sql

    DROP DATABASE X;
    CREATE DATABASE X
    

    Liquibase does have a dropAll command which can be used to drop everything in a schema, but it is slower than drop/create database on mysql and may miss some database objects.