2016-03-21 126 views
1

我以前的版本使用grails-database-migration插件一段時間,從來沒有任何大問題。然而,最近我升級了整個項目的Grails 3.0.9,並做了一些額外的開發,該行爲如下:grails升級到grails後數據庫遷移插件問題3

  1. 進口當前督促DB結構到本地機器(即DB副本是沒有的最新變化和新的實體)

  2. 執行:grails -Dgrails.env=staging dbm-gorm-diff changlog.xml

我預計在這一點上什麼是與現有實體和新的所有更改新changlog.xml文件。

我得到什麼:

  • 新定義的實體自動得到加入到數據庫中。
  • 在changlog.xml的變化只包括已經存在的表的變化,如: enter image description here

另外,如果我嘗試運行grails -Dgrails.env=staging run-app

ERROR grails.boot.GrailsApp - Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springLiquibase_dataSource': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: liquibase.integration.spring.SpringLiquibase.createDatabase(Ljava/sql/Connection;Lliquibase/resource/ResourceAccessor;)Lliquibase/database/Database; FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':bootRun'. Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1 ...

...

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. | Error Failed to start server (Use --stacktrace to see the full trace)

這裏是我的應用程序的一部分.yml

dataSource: 
    pooled: true 
    url: jdbc:mysql://127.0.0.1:3306/triz?useUnicode=yes&characterEncoding=UTF-8 
    driverClassName: "com.mysql.jdbc.Driver" 
    jmxExport: true 
    username: root 
    password: password 
    dialect: org.hibernate.dialect.MySQL5InnoDBDialect 
    properties: 
     jmxEnabled: true 
     initialSize: 5 
     maxActive: 50 
     minIdle: 5 
     maxIdle: 25 
     maxWait: 10000 
     maxAge: 600000 
     timeBetweenEvictionRunsMillis: 5000 
     minEvictableIdleTimeMillis: 60000 
     validationQuery: SELECT 1 
     validationQueryTimeout: 3 
     validationInterval: 15000 
     testOnBorrow: true 
     testWhileIdle: true 
     testOnReturn: false 
     jdbcInterceptors: ConnectionState 
     defaultTransactionIsolation: 2 

environments: 
    development: 
     dataSource: 
      dbCreate: create 
#   url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE 
    test: 
     dataSource: 
      dbCreate: update 
      url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE 
    staging: 
     dataSource: 
      url: jdbc:mysql://127.0.0.1:3306/triz_staging?useUnicode=yes&characterEncoding=UTF-8 

和gradle.build

buildscript { 
    ext { 
     grailsVersion = project.grailsVersion 
    } 
    repositories { 
     mavenCentral() 
     mavenLocal() 
     maven { url "https://repo.grails.org/grails/core" } 
    } 
    dependencies { 
     classpath "org.grails:grails-gradle-plugin:$grailsVersion" 
     classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0' 
//  classpath 'com.bertramlabs.plugins:less-asset-pipeline:2.6.7' 
     classpath "org.grails.plugins:hibernate:4.3.10.5" 
     classpath 'org.grails.plugins:database-migration:2.0.0.RC4' 
    } 
} 
... 
... 
dependencies { 
... 
    compile 'org.liquibase:liquibase-core:3.3.2' 
    runtime 'org.grails.plugins:database-migration:2.0.0.RC4' 
} 

UPDATE 我有另一種方式來解決這個問題: 我的計劃是基於我目前的PROD數據庫更新日誌,然後生成我做出改變的差異。聽起來簡單直接;然而,它沒有按預期工作。下面是我做的:

  1. 甩刺DB
  2. 刪除liquibase表
  3. 運行:grails dbm-generate-changelog changelog-init.xml --add 在這一點上,我預計的changelog-導入init.xml包含DB的當前狀態。但是,它首先應用了基於我的模型的更改,然後嘗試生成差異。最後,我結束了一個更改日誌,其中包括我的整個現有數據庫,其中應用了來自gorm的更改。

我在這裏做錯了什麼?

補充意見

它看起來像,每當我嘗試運行任何遷移相關的命令是,Grails應用之前,所有的變化,甚至通過我的配置說:

staging: 
     dataSource: 
      dbCreate: ~ 
      url: jdbc:mysql://127.0.0.1:3306/triz_staging?useUnicode=yes&characterEncoding=UTF-8 
      properties: 
       jmxEnabled: true 

而且完全試過刪除dbCreate。沒有改變任何東西... 我完成了,不知道下一步移動到哪裏!

回答

0

嗯,這是一筆交易...... 我不確定這是否是真正的原因,但我所做的是將數據源配置從application.yml移動到application.groovy並且一切恢復正常。

我很樂意聽到你的想法。

感謝。