Database migration (or database refactoring as this technique is sometimes called as well) tools allow you to apply data definition language (DDL) statements like “CREATE TABLE …” or “ALTER …” to databases in an automated, consistent and traceable manner instead of either having every developer involved change the database schema whenever he or she sees fit or – probably even worse – requiring a DBA to review and approve each and every database change however minute, an approach which favours stability over change at all costs and hence severely hampers development speed.
If you worked without automated database migrations you’d have to apply structural database changes required by software changes manually. Not only are manual changes tedious and hence should be automated (see the Three Virtues) but they’re also error-prone in that they tend to be forgotten as well as often work differently in different environments such as production servers.
Using such a tool in your daily development process therefore really is a no-brainer.
For Java environments there’s a variety of different tools for this purpose, like Liquibase for example.
A particularly simple and easy-to-use database migration tool for Java however is
Flyway, which enables you to “evolve your database schema easily and reliably across all your instances“. The Flyway website explains in easy terms why database migrations are useful in the first place and how Flyway approaches this important component of the software development process.
Flyway can be used in various ways like purely as a command-line tool, as a Maven plugin, via Ant or Gradle and even programmatically from your Java code.
In order to do its work Flyway adds a simple schema_version table to your database that contains metadata about the current version of the database and the migrations that have already been applied to it.
The one aspect that makes Flyway particularly stand out from competing tools is that it uses plain and simple SQL scripts in order to apply migrations. No weird DSLs or XML dialects to learn! Just use SQL like you’re used to!