问题
Hi everyone I am encountering a problem/confusion with grails database migration plugin.
Resources used for studying-
- Official Grails Database Migration Plugin documentation- http://grails-plugins.github.io/grails-database-migration/docs/manual/guide/introduction.html
- Database migration example- http://grails.github.io/grails-howtos/en/manageDatabases.html
Now with the help of these I am very well able to migrate or do changes to my database on the local machine which has grails installed and working correctly.
The problem is that the production server is deployed online and I always upload my WAR file to deploy on apache tomcat. So it basically runs on JAVA so grails is not installed on the ubuntu machine. Now how will I migrate mysql database on the server?
回答1:
Add below config in your Config.groovy file. Migration will run during WAR deployment.
//===========================DATA MIGRATION============================
//Run changelog.groovy during application deployment on server?
grails.plugin.databasemigration.updateOnStart = true
//File used to run the db migration scripts
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.groovy']
//Absolute path of changelog.groovy in the app base dir
grails.plugin.databasemigration.changelogLocation = 'migrations'
// the default schema to use when running auto-migrate on start
//grails.plugin.databasemigration. updateOnStartDefaultSchema ='schema' // You may not need this in MYSQL
//=====================================================================
Based on the above configuration, this is how your folder structure should be:
your-grails-project
--migrations/
--changelog.groovy
--migration1.groovy
--migration2.groovy
changelog.groovy
databaseChangeLog = {
include file: 'migration1.groovy'
include file: 'migration2.groovy'
}
来源:https://stackoverflow.com/questions/25053091/grails-database-migration-on-deployed-server