Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Flyway or Liquibase generate an update script instead of updating the database directly?

First, a little background. I have a set of Java applications, some based on JPA, some not. To create my databases I am currently using Hibernates schema export to generate create scripts for those using JPA. Those not using JPA I generate the scripts by hand. These are then run during application installation using ANT. For updates the application installer simply applies update scripts to the database.

To improve the management of database updates I have been looking at Flyway and Liquibase. Both seem to almost do what I want, (aside: I am preferring Flyway at the moment because of all the pre-existing SQL/DDL scripts we have). The issue I can see is that they both update the database directly. This is fine for a lot of installations but not all.

What I would like to do is run Flyway/Liquibase against the database and generate an update script that incorporates all the updates needed to bring the database up to date - including any changes Flyway/Liquibase needs to make to its own tables. This would allow me (or more importantly a database admin) to run the update script outside of the application(s) to update the database. I could then use Flyway/Liquibase within my application purely to verify that the database is up to date.

Is it possible to do this with Flyway or Liquibase or any other tool for that matter?

like image 754
pillingworth Avatar asked Jan 23 '13 14:01

pillingworth


People also ask

What is the difference between Liquibase and Flyway?

Defining a Change. Flyway uses SQL for defining a change. On the other hand, Liquibase provides flexibility to specify a change in different formats including SQL such as XML, YAML, and JSON. With Liquibase we can work with database-agnostic languages and easily apply schema changes to different database types.

What is Flyway and how does it work?

Flyway is an open-source database migration tool. It strongly favors simplicity and convention over configuration. It is based around just 7 basic commands: Migrate, Clean, Info, Validate, Undo, Baseline and Repair.

Is Liquibase better than Flyway?

While both tools are based on Martin Fowler's Evolutionary Database, there are many differences in what these tools offer. Here's where Liquibase and Flyway differ. The bottom line is that Liquibase is more powerful and flexible — covering more database change and deployment use cases than Flyway.


1 Answers

Liquibase handles it quite fine. It looks at your database at the current state, finds unapplied changesets and generates an SQL script with update command in sql output mode.

Using a proper database migration tool instead of Hibernate generator is the way to go in any case, sooner or later you'll end up with a situation that Hibernate does not support. For us it was dropping an unique index and replacing it with another. You can also enable hibernate.hbm2ddl.auto=validate to feel safe about the compatibility between database structure and entity beans.

like image 105
Mirko Adari Avatar answered Oct 18 '22 18:10

Mirko Adari