Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using liquibase on existing schema

Tags:

liquibase

I've read about how you can generate changelog.xml from an existing schema. That's fine, but I have existing systems that I don't want to touch, except to bring in new changes. I also have completely new systems which require all changes be applied.

So, I want to get liquibase to only perform migrations from changeset X when running on an existing system. I.e. that system's DB is at revision X-1 (but no liquibase sys tables), and I don't want any preceeding migrations applied.

Many thanks, Pat

like image 997
pat Avatar asked Aug 02 '11 12:08

pat


2 Answers

I would recommend a slightly different approach, as commented in this Liquibase forum thread

  1. generate a changelog from your existing schema. The liquibase CLI can do that for you. I usually take the resulting XML and smooth it out a bit (group related changes into single changelogs, do vendor-specific cleanups and so on), but Liquibase does most of the legwork.

  2. run that changelog against the existing database (changelogSync command), but only marking it as applied (without actually modifying the schema).

  3. use liquibase for applying new changes from that point on.

like image 154
fglez Avatar answered Sep 21 '22 01:09

fglez


I think the easiest would be to execute the initial setup on an empty database at first and export the entry(ies) liquibase does insert into the DATABASECHANGELOG table. Then I'd export these entries and insert them manually into one of the target databases into their DATABASECHANGELOG table, so liquibase does not execute the "change" there again.

Of course I'd test all that with test dumps on a test machine... :)

like image 41
Thomas Keller Avatar answered Sep 24 '22 01:09

Thomas Keller