1
votes

When starting to use Liquibase on an existing database, it is often useful, particularly for testing, to have a way to generate the change log to create the current database schema. Liquibase allows you to do this with the “generateChangeLog” command_line command. However this command will generate database change log in XML format only.

So how to generate the change log in SQL format to create the current database schema ? Does it exist any way to convert the database change log in XML format to SQL format ? If not, is there any extension point in Liquibase API to add this feature ?

1
Which RDBMS are you using?Eric Hauenstein
I use mainly Oracle 11.0.2.x.bgillis
After you executed generateChangeLog you can run updateSQL (against an empty database). Not convenient but a way to generate SQL.Jens
Thanks Jens... that's indeed a very clever way to solve this. But as you said, you will need an additional empty database to run the command.bgillis
An example of how @Jens solution would work: stackoverflow.com/questions/8397488/…Mark O'Connor

1 Answers

2
votes

There is no support currently to generate SQL, but you would be able to write an extension to do it. The *Serializer classes like liquibase.serializer.core.xml.XMLChangeLogSerializer take a changelog object and output into whatever format you want.

With something like FormattedSqlChangeLogSerializer that overrides getValidFileExtensions() to return new String[]{"xml"} you can just run generateChangeLog with outputFile=some.file.sql and get the SQL you generated in your custom serializer class.

The extension system will allow you to create this class in a custom jar.