我遵循了这个链接http://grails-plugins.github.io/grails-database-migration/3.0.x/index.html#introduction的指示
首先,我在application.yml中添加了所需的行:
buildscript {
dependencies {
...
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}
dependencies {
...
compile 'org.grails.plugins:database-migration:3.0.0'
compile 'org.liquibase:liquibase-core:3.5.3'
}
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}然后运行"grails generate changelog.groovy“,然后运行”“,然后将视图添加到changelog.groovy文件中:
databaseChangeLog = {
changeSet(author: "xxx (generated)", id: "1490002519504-99", contexts: 'Test') {
createView("""
SELECT dbo.Client.ClientNo, dbo.Client.ClientName
FROM dbo.Client INNER JOIN
dbo.ClientRole ON dbo.Client.ClientNo = dbo.ClientRole.ClientNo AND dbo.ClientRole.RoleType = 2
""", viewName: 'dbo.vw_supplier'
)
}
changeSet(author: "xxx (generated)", id: "1490002519504-1", contexts: 'Test') {
createTable(tableName: "orders") {
column(autoIncrement: "true", name: "id", type: "bigint") {
constraints(primaryKey: "true", primaryKeyName: "PK__orders__3213E83F6FCA6F65")
}我在application.groovy中添加了以下行:
grails.plugin.databasemigration.updateOnStartFilename = 'changelog.groovy'
grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartContexts = ['Test']经过一些尝试,我评论了最后一行,不使用“上下文”,但它没有改变任何东西。
我也改变了引导开发,创建-下降到零。我从数据库中删除了所有表,并运行"grails“,然后创建所有表,但不创建添加到"changelog.groovy”中的视图。这些表都是在没有任何列的情况下创建的。我还收到了一条奇怪的信息:
"INFO 2017-03-20 12:54: liquibase: Can not use class org.grails.plugins.databasemigration.liquibase.GormDatabase as a Liquibase service because it does not have a no-argument constructor"
buildscript {
repositories {
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.11.6"
classpath "org.grails.plugins:hibernate5:6.0.4"
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}我的项目现在完全停顿了。
发布于 2017-03-20 13:57:59
您的create语法是不正确的,请添加要创建视图的字符串的selectQuery=。
createView(selectQuery="""
SELECT dbo.Client.ClientNo, dbo.Client.ClientName
FROM dbo.Client INNER JOIN
dbo.ClientRole ON dbo.Client.ClientNo = dbo.ClientRole.ClientNo AND dbo.ClientRole.RoleType = 2
""", viewName: 'dbo.vw_supplier'
)https://stackoverflow.com/questions/42903789
复制相似问题