Migrations to Play: Why not use Hibernate Schema Update?

First module I wrote for Play framework was a database migration module based on c5-db-migration. It's really simple, it has play command for creating a new migration file using timestamp for versioning. And then it has plugin, which loads the migrations to the database on application startup.

So after using the module for 2 months I got this idea on how I might be able to improve it: Since hibernate can generate the database changes if you configure the jpa.ddl=update, why not use the hibernate schema update to generate the changes to a migration which you could then review and adjust manually if needed?

After some exploration on the hibernate sources and plenty of trial and error I ended up with the following code:

It prints the update statements to System.out after comparing the database with the models. It also reads the hibernate configuration from the application.conf which is important for me since we use a custom naming strategy. Next step is to add this to our migration module.

1 comment: