Question

I want to understand better how Liquibase executes change sets.

1)

a) For example I have a change log with 4 change sets and I execute updateDatabase (http://www.liquibase.org/documentation/ant/updatedatabase_ant_task.html). Liquibase will execute 4 change sets.

b) If I run the same change log once again Liquibase not execute any set.

c) If I will add a new change set to the change log and will run the change log Liquibase will execute the new change set only.

Questions:

  • How Liquibase knows what change sets to execute?

  • How Liquibase knows what change sets already executed?

2) How change set ID is important? Can I change it after a change log execution?

3) How change set author is important? Can I change it after a change log execution?

4) What happens if I will execute the rollbackDatabase (http://www.liquibase.org/documentation/ant/rollbackdatabase_ant_task.html)? How Liquibase knows what change sets to rollback?

a) What happens if I will execute the rollback after 1 a). Will Liquibase call to rollback element that is located in each change sets (4 rollback elements)?

b) What happens if I will execute the rollback after 1 b). How Liquibase will know not to call to any to rollback element?

c) What happens if I will execute the rollback after 1 c). Will Liquibase call to rollback element of only the new change set?

Was it helpful?

Solution

I can answer a few questions, perhaps not all though.

  1. c. - Liquibase creates 2 new tables in the database when you do the first update. The main table is DATABASECHANGELOG, and that is used to keep track of what change sets have been applied to the database. Liquibase uses a couple of ways to identify each changeset - the id, author, and path are used as a composite key. Liquibase also generates a checksum of each changeset that is used to tell whether the changeset has been altered after being applied to the database.

  2. and 3. Because the change set id and author are used as part of the primary key, if you deploy, then change either one of those, you may run into unexpected behavior on subsequent deploys. I think that the id and author are also part of the checksum calculation, so that might affect things also. I would recommend that you do not change those after deploying.

  3. Rollback uses the same mechanism to know what change sets to roll back. When you roll back you have to specify in some way what changes to undo - see this page for more info: http://www.liquibase.org/documentation/rollback.html

The rollback identification mechanisms are by tag (which means you have to apply tags when you deploy), by date (Liquibase keeps track of when each changeset was deployed), or by number (which implicitly uses the date/time of when each changeset was deployed).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top