1
votes

I'm using Liquibase to generate a DB scheme from existing H2 database. I use the following:

liquibase  --driver=org.h2.Driver --classpath=./h2-1.4.199.jar --changeLogFile=db.schema.sql --url="jdbc:h2:mem:testdb" --username=sa --password= --logLevel=debug generateChangeLog

So, absolutely default values in order to connect to the H2 instance. But the command above generates an empty changelog file (just some basic Liquibase headers).

I tried to use different urls (h2 in file), I tried to set different password and username, I even tried to define defaultSchemaName parameter, but still the same. Liquibase maven plugin says: No changes found, nothing to do Liquibase without maven plugin says: Liquibase command 'generateChangeLog' was executed successfully.

I also tried to put invalid credentials (username or password), but still the same.

1

1 Answers

2
votes

generateChangeLog command exports data from the specified database. It means that such database should exist and be populated with some data.

There is no point to specify the in-memory embedded URL jdbc:h2:mem:testdb here. Each process have own memory and own in-memory databases. Liquibase will definitely see an empty database here inside its own memory.

You need to create a normal persistent database with your application and use its URL here. I strongly suggest you to specify the absolute database path (without file name extension) in the database URL to be sure that the same database will be used by your application and by Liquibase. Note that you can't use the embedded database by two applications at the same time without additional parameters (auto-server mode), so you need to close the database in your application before you'll launch Liquibase. As an alternative you can start the H2 Server process and use remote URLs or you can use the auto-server mode.

You can also append ;IFEXISTS=TRUE to the database URL for Liquibase only. It will prevent accidental silent creation of a new empty database in it.