Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use liquibase diffChangeLog with the current changelog as reference (to generate incremental change set)

Tags:

liquibase

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...

like image 921
Ian Rogers Avatar asked Jun 02 '14 20:06

Ian Rogers


People also ask

What is the purpose of adding changesets to your changelog?

Liquibase Concepts A change is contained in a changeset and changesets are added to the changelog in the order they need to be deployed. Simply put – a changelog contains an ordered list of changesets, and a changeset contains a change.

What is a change set in Liquibase?

The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.

How do Liquibase changelogs work?

Liquibase uses a changelog to sequentially list all changes made to your database. Think of it as a ledger. It is a file that contains a record of all your database changes (changesets). Liquibase uses this changelog record to audit your database and execute any changes that are not yet applied to your database.


1 Answers

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.

like image 152
Nathan Voxland Avatar answered Sep 30 '22 16:09

Nathan Voxland