Database Migrations: Fail when database is out of date

Christian Nelson ·

The latest release of the Carbon Five Database Migration maven plugin supports a new goal: check. The check goal fails the build if the database isn’t up to date. That is, if there are pending migrations the plugin produces a clear message explaining that the database is out of date and lists the pending migrations. Run mvn test and see something like this:

[INFO] ————————————————————————
[INFO] Building Gearlist – Data Access
[INFO] task-segment: [test] [INFO] ————————————————————————
[INFO] [db-migration:check {execution: default}] [INFO] Checking jdbc:mysql://localhost/gearlist_test using migrations at src/main/db/migrations/.
[INFO] Loaded JDBC driver: com.mysql.jdbc.Driver
[WARNING] There are 2 pending migrations:


Execute db-migration:migrate to apply pending migrations.
[INFO] ————————————————————————
[INFO] ————————————————————————
[INFO] There are 2 pending migrations, migrate your db and try again.

It’s very easy to include the check goal in your build lifecycle if you’re already using the db-migration-maven-plugin.


Check out the project home for additional documentation and details. There’s also a simple, complete example application showing off this configuration.


Christian Nelson
Christian Nelson

Christian is a software developer, technical lead and agile coach. He's passionate about helping teams find creative ways to make work fun and productive. He's a partner at Carbon Five and serves as the Director of Engineering in the San Francisco office. When not slinging code or playing agile games, you can find him trekking in the Sierras and playing with his daughters.