2

I've got an existing production DB, and a development DB with some schema differences. Neither have used Liquibase before. How can I achieve the following:

  1. Compute a difference between production and development.
  2. Apply the delta to production,
  3. End up with both production (and dev) schema under control of Liquibase.
user3364825
  • 1,541
  • 1
  • 15
  • 23

3 Answers3

3

Here is what I ended up with ($LIQUIBASE expands to the Liquibase command line tool configured for the particular DB I was using).

Generate a baseline changelog from the current state of the Production DB:

$LIQUIBASE --url=$PROD_URL --changeLogFile=changeLog.xml generateChangeLog

Record Production as being in sync with the change log:

$LIQUIBASE --url=$PROD_URL --changeLogFile=changeLog.xml changeLogSync

Calculate the differences between Development and Production, and append them to the change log file:

$LIQUIBASE --url=$PROD_URL --referenceUrl=$DEV_URL --changeLogFile=changeLog.xml diffChangeLog

Bring Production in sync with Development:

$LIQUIBASE --url=$PROD_URL --changeLogFile=changeLog.xml update

Record Development as being in sync with the change log:

$LIQUIBASE --url=$DEV_URL --changeLogFile=changeLog.xml changeLogSync
user3364825
  • 1,541
  • 1
  • 15
  • 23
2

You would start by generating a changelog for the development database, using the generateChangelog command, documented here: http://www.liquibase.org/documentation/generating_changelogs.html

When you generate the changelog, Liquibase will also create and initialize the two database tables (DATABASECHANGELOG and DATABASECHANGELOGLOCK) that it uses to keep track of what changesets have been applied to the database.

Next, you want to diff the two databases and have liquibase generate the differences as a separate changelog using the diffChangelog command: http://www.liquibase.org/documentation/diff.html

The diff changelog can be included as is, or copied into an existing change log. If the diff command is passed an existing change log file, the new change sets will be appended to the end of the file.

Finally, you deploy the changelog to the production environment.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
  • Thanks, I've given what you've suggested a go, but deploying the changelog to prod doesn't seem to make any changes, so I presume I'm doing something wrong somewhere along the line. I don't suppose you could add some sample commands to your answer so I can make sure I'm on the right track? – user3364825 Mar 21 '14 at 14:33
  • Here's what I've been doing so far: https://gist.github.com/anonymous/9688574 The generated changelog for production doesn't make much sense, though. – user3364825 Mar 21 '14 at 15:18
0

5.3 part of this tutorial answers your question I guess.

http://www.baeldung.com/liquibase-refactor-schema-of-java-app

This uses maven in java but I think plain liquibase commands also can do it.

Erlan
  • 2,010
  • 1
  • 22
  • 31