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.
当开始在现有数据库上使用Liquibase时,有一种生成更改日志以创建当前数据库模式的方法通常很有用,尤其是在测试中。Liquibase允许您使用“generateChangeLog”command_line命令执行此操作。然而,这个命令只会以XML格式生成数据库更改日志。
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 ?
那么如何以SQL格式生成更改日志来创建当前的数据库模式呢?是否存在将XML格式的数据库更改日志转换为SQL格式的方法?如果没有,在Liquibase API中是否有任何扩展点来添加这个特性?
1 个解决方案
#1
2
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.
目前还不支持生成SQL,但是您可以编写扩展来实现它。*序列化器类,如liquibase. seriali泽.core.xml。XMLChangeLogSerializer使用一个changelog对象并将其输出到您想要的任何格式。
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.
使用类似于FormattedSqlChangeLogSerializer的方法,可以覆盖getValidFileExtensions()来返回新字符串[]{“xml”},您可以使用outputFile=some.file来运行generateChangeLog。sql并获取您在自定义序列化器类中生成的sql。
The extension system will allow you to create this class in a custom jar.
扩展系统将允许您在自定义jar中创建该类。
#1
2
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.
目前还不支持生成SQL,但是您可以编写扩展来实现它。*序列化器类,如liquibase. seriali泽.core.xml。XMLChangeLogSerializer使用一个changelog对象并将其输出到您想要的任何格式。
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.
使用类似于FormattedSqlChangeLogSerializer的方法,可以覆盖getValidFileExtensions()来返回新字符串[]{“xml”},您可以使用outputFile=some.file来运行generateChangeLog。sql并获取您在自定义序列化器类中生成的sql。
The extension system will allow you to create this class in a custom jar.
扩展系统将允许您在自定义jar中创建该类。