13
votes

I have an existing database and have used the generateChangeLog command line to create the initial changelog. This works fine :-)

But now I want the developers to use all the tools/processes they know/use already to develop the database and code and use a script to generate any incremental change sets as appropriate.

That is: do a diff against the current state of the developer's database (url/username/password in the properties file) using the current changelog (changeLogFile in the properties file) as the base reference.

There seems no easy way to do this - the best I've come up with is:

  1. Create a new temporary database.
  2. Use liquibase to initialise the temp database (to what is currently in the changelog) by overriding the connection url: liquibase --url=jdbc:mysql://localhost:3306/tempbase update
  3. Use liquibase to generate a changeset in the changelog by diff'ing the two databases: liquibase --referenceUrl=jdbc:mysql://localhost:3306/tempbase --referenceUsername=foo --referencePassword=baz diffChangeLog
  4. Drop the temporary database.
  5. Synchronise the changeset: liquibase changelogSync

but there must be a better way...

2

2 Answers

2
votes

You are right that liquibase cannot compare a changelog file with a database. The only real option is to compare your developer database with an actual liquibase-managed database, or at least one temporarily created.

What I would suggest as the better way is to consider shifting the developers to author liquibase changeSets in the first place. It is different tooling than they may be used to, but it has the huge advantage that they will know that the change they wanted to make is the one that will make it all the way to production. Any diff-based process (such as using diffChangeLog) will usually guess right about what changed, but not always and those differences are often not noticed until into production.

Liquibase has various features such as formatted SQL changelogs that are designed to make the transition from developers working directly against their database to tracking changes through Liquibase because once that transition is made many things get much easier.

0
votes

With Liquibase Pro you can create a snapshot file that accomplishes the same thing. And then use the snapshot file to compare your database updates.

https://www.liquibase.org/documentation/snapshot.html I mention Pro because it takes care of stored logic comparisons as well.