我使用了较早版本的grails-database-migration插件已有一段时间,但从未遇到过任何大问题。但是,最近我将整个项目升级到grails 3.0.9,并进行了一些其他开发,其行为如下:
grails -Dgrails.env=staging dbm-gorm-diff changlog.xml
在这一点上,我期望的是新的changlog.xml文件,其中包含现有实体和新实体的所有更改。
我得到的是:
另外,如果我尝试运行
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)
这是我的application.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'
}
更新
我有另一种方法来解决此问题:
我的计划是根据当前的产品数据库生成一个变更日志,然后为所做的更改生成差异。听起来简单明了;但是,它没有按预期进行。这是我所做的:
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
。没什么改变...我完成了,不知道下一步要去哪里!!!
最佳答案
好吧,这是一笔交易...
我不确定这是否是真正的原因,但是我所做的只是将数据源配置从application.yml
移到application.groovy
,一切恢复正常。
我很高兴听到想法。
谢谢。
关于spring - 升级到grails 3后,grails数据库迁移插件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36122430/