Grails database migration on deployed server

半城伤御伤魂 提交于 2020-01-13 11:39:29

问题


Hi everyone I am encountering a problem/confusion with grails database migration plugin.

Resources used for studying-

  1. Official Grails Database Migration Plugin documentation- http://grails-plugins.github.io/grails-database-migration/docs/manual/guide/introduction.html
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!