Bruno Krebs
Bruno Krebs

Reputation: 3159

Grails database migration plugin updateOnStart is not working

I need some help here. I have configured database migration plugin as the documentation says:

grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.groovy']

This works fine when running 'grails run-app'. My database is migrated as expected, but how would I get this behavior when deploy my 'grails war' artifact?

I have tested it on tomcat, by manually copying the artifact to tomcat/webapps folder, but during deployment, hibernate complains about missing columns (the one that should have been created by the database migration plugin).

Any ideas?

Thanks!

Upvotes: 5

Views: 1791

Answers (3)

zsando
zsando

Reputation: 11

See this answer to a similar question https://stackoverflow.com/a/25053160/3939511

I find that the default value for grails.plugin.databasemigration.changelogLocation at compile time is correct to have your change-logs included in the production war. I.e. I don't set/change this property in Config.groovy at compile time.

But in deployment I set grails.plugin.databasemigration.changelogLocation = 'migrations', as the change-logs end up in WEB-INF/classes/migrations/ (as groovy scripts, not compiled classes).

Upvotes: 1

Manuel Vio
Manuel Vio

Reputation: 506

Are you sure that those two lines of code are available in production environment too?

This is an example of what I normally do in my applications:

environments {
    development {
        grails.plugin.databasemigration.updateOnStart = true
        grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.groovy']
        // ... other useful development settings
    }
    test {
        grails.plugin.databasemigration.updateOnStart = true
        grails.plugin.databasemigration.autoMigrateScripts = ['RunApp','TestApp']
        grails.plugin.databasemigration.forceAutoMigrate = true
        grails.plugin.databasemigration.dropOnStart = true
        if (loadTestData) {
            grails.plugin.databasemigration.updateOnStartFileNames = ['testchangelog.groovy', 'testdata.groovy']
        } else {
            grails.plugin.databasemigration.updateOnStartFileNames = ['testchangelog.groovy']
        // ... something test-related
        }
    }
    production {
        grails.plugin.databasemigration.updateOnStart = true
        grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.groovy']
        // ... production config settings
    }
}

Also, be sure to comment out relevant dbCreate entries in DataSource.groovy to avoid issues with migrations.

Upvotes: 3

dellyjm
dellyjm

Reputation: 426

I believe if you do a dbm-update that create the patches for you in the destination database.

Grabbed this from the Grails site. http://grails-plugins.github.io/grails-database-migration/docs/manual/ref/Update%20Scripts/dbm-update.html

dbm-update Purpose

Updates a database to the current version.

Description

Runs all un-run changeSets from the changelog. Executes against the database configured in DataSource.groovy for the current environment (defaults to dev).

Usage:

Upvotes: 0

Related Questions