部署的服务器上的Grails数据库迁移

时间:2021-03-09 19:22:03

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

大家好,我遇到了grails数据库迁移插件的问题/混淆。

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. 官方Grails数据库迁移插件文档 - http://grails-plugins.github.io/grails-database-migration/docs/manual/guide/introduction.html

  3. Database migration example- http://grails.github.io/grails-howtos/en/manageDatabases.html
  4. 数据库迁移示例 - 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.

现在在这些帮助下,我能够在本地机器上迁移或更改我的数据库,该机器已安装grails并正常工作。

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?

问题是生产服务器是在线部署的,我总是上传我的WAR文件以在apache tomcat上部署。所以它基本上运行在JAVA上,所以grails没有安装在ubuntu机器上。现在我将如何在服务器上迁移mysql数据库?

1 个解决方案

#1


4  

Add below config in your Config.groovy file. Migration will run during WAR deployment.

在Config.groovy文件中添加以下配置。迁移将在WAR部署期间运行。

//===========================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'
}    

#1


4  

Add below config in your Config.groovy file. Migration will run during WAR deployment.

在Config.groovy文件中添加以下配置。迁移将在WAR部署期间运行。

//===========================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'
}