Package Grails DBMigrations in your WAR File

June 10, 2008 - 1 minute read -
grails Automation

The Grails DBMigrate Plugin is a handy way to give you control over the generation of your database if you don't want Grails to auto-munge your schema. It works fine in development, but when you create a WAR for deployment on another machine the Migrations are not packaged in the WAR so the database can't be created or updated.

Packaging DBMigrate Scripts for Deployment

Here's the quick solution to package your DBMigrations in your WAR file.

Just add this to your Config.groovy file and when you generate the WAR the migrations will be included and found by the Plugin.

grails.war.resources = {stagingDir ->
    copy(todir: "${stagingDir}/WEB-INF/classes/grails-app/migrations") {
        fileset(dir:"grails-app/migrations")
    }
}

Aside

The only problem with DBMigrate is that it doesn't handle creating or updating Stored Procedures and Functions which means if you want to use those - for Reporting purposes lets say - you're out of luck currently.