Can I automatically convert Liquibase changelog files in the XML format to the YAML format?
-
You should consider if the change from xml to yml will cause a change in the checksum of the changelog. – senjin.hajrulahovic Aug 01 '18 at 13:31
3 Answers
There is nothing built in, but you can easily do it with a little scripting.
Some starting points:
liquibase.parser.ChangeLogParserFactory.getInstance().getParser(".xml", resourceAccessor).parse(...)
will return a DatabaseChangeLog object representing the changelog file.
liquibase.serializer.ChangeLogSerializerFactory.getInstance().getSerializer(".yaml").write(...)
will output the changeSets in the DatabaseChangeLog object out to a file in yaml format

- 15,453
- 2
- 48
- 64
-
I published a simple script on github: https://github.com/GoGoris/liquibase-changelog-converter/blob/master/src/main/java/gogoris/Xml2Yml.java – GoGoris Oct 03 '18 at 12:06
-
3Corrected link: https://github.com/GoGoris/liquibase-changelog-converter/ – Ruslan Stelmachenko Aug 17 '19 at 22:10
I know this is a bit late of an answer; however, I was looking into using Liquibase for a project at work and was looking for something to do what he OP wanted. I saw Nathan Voxland's answer and made a command-line utility written in Java to convert this. The code can be found at here on Github. Feel free to modify it or fix it and send PRs; I literally wrote it in an hour or so, so please be easy on judging the code base :). Hopefully this will help out the next person that is looking for a similar tool and stumbles here.

- 5,753
- 72
- 57
- 129

- 401
- 5
- 9
Smart way is to directly generate yaml instead of xml, Liquibase provides this functionality OOB.
You only need to change the extension of output changeLogFile file to .yaml
and liquibase will understand you nicely (tested with liquibase-3.6.0).
For example: I ran this command for my Postgres DB:
liquibase --driver=org.postgresql.Driver
--classpath=\path\to\postgresql-9.0-801.jdbc4.jar
--changeLogFile=D:\Liquibase\changeLog.yaml
--url="jdbc:postgresql://localhost:5432/db_name"
--username=postgres
--password=postgres
--logLevel=debug generateChangeLog
Caution: New lines were added for readability purpose.
Now you know what will happen if you change the extension of output file to .xml
PS: If liquibase command doesn't work try the same with java -jar liquibase.jar
.

- 1,029
- 2
- 14
- 29
-
1Good answer, but I think that OP wants to convert already existing xml changelogs to yml and not to generate them. Anyway your answer was helpful. Thanks. – senjin.hajrulahovic Aug 01 '18 at 13:29
-
Sometimes it is unclear what OP wanted to do and what he can actually do. May be the OP generated xml and tried converting them. Since the question was very old I didn't asked about it. Happy that it helped you. – Ubercool Aug 02 '18 at 10:31
-
Helped me too. Liquibase documentation about generation didn't mention YAML so it wasn't obvious that it could detect from the extension and create appropriately. – Pool Dec 12 '18 at 13:13