0

I have two database schema files, both of them are empty. Let's say that there's a version 1 and a version 2 of the database schema in db.v1.sql and db.v2.sql.

I'd like create a diff which will update a database with the schema db.v1.sql to db.v2.sql.

Is Liquibase is capable to do that? Is there another tool to do it from Java?

4spir
  • 1,174
  • 2
  • 15
  • 31

1 Answers1

2

Yes, this is do-able using Liquibase.

  1. Create a changelog.xml file that lists the .sql files as separate changesets. Think of this file as 'tempChangeLog.xml' In this file, add a label attribute to each of the changesets with "v1" or "v2".
  2. Use liquibase update to apply the first label to a first database instance.
  3. Use liquibase generateChangelog to "convert" the sql to liquibase xml changesets. This will be your 'realChangeLog.xml'
  4. Modify the 'realChangeLog.xml to add "v1" label attribute to all the changesets.
  5. Use liquibase update with 'tempChangeLog.xml' to apply the second label to a second database instance.
  6. Use the liquibase diffChangelog command to compare database instance 1 with database instance 2, appending the changes to 'realChangeLog.xml'
  7. Modify 'realChangeLog.xml' again to add "v2" labels to all the new changesets.

You will now have a changelog.xml that can be used to update a database to either v1 or v2.

Synchronizing new changes with your ORM is a separate exercise.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
  • I'd like to have an sql file output. Is it also possible? The reason is that I'd like to do some custom changes in the file and exemine it before using it as an update on the real db. – 4spir Sep 30 '15 at 14:39
  • @zeal See: http://stackoverflow.com/questions/8397488/comparing-databases-and-genrating-sql-script-using-liquibase/ – Mark O'Connor Oct 03 '15 at 10:51
  • It would be great to do this without using an active connection to the database, however I can't find a tool to do that easily, so I accept your aswer. – 4spir Oct 05 '15 at 11:25