Grail 数据迁移插件
Grail data-migration-plugin
我按照这个 link 中的说明进行操作
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 dbm-generate-changelog changelog.groovy" 之后:"grails dbm-changelog-sync"
然后我在 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']
经过一些尝试,我将最后一行注释为不使用 "contexts",但它并没有改变任何东西。
我还在 bootstrap 中更改了开发 create-drop 到 none。
我从数据库中删除了所有表并且 运行 "grails dbm-update"
然后它创建所有表,但不创建我添加到 "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'
}
}
我的项目现在完全停滞了。
您创建视图的语法不正确,在字符串前面添加 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'
)
我按照这个 link 中的说明进行操作 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 dbm-generate-changelog changelog.groovy" 之后:"grails dbm-changelog-sync" 然后我在 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']
经过一些尝试,我将最后一行注释为不使用 "contexts",但它并没有改变任何东西。
我还在 bootstrap 中更改了开发 create-drop 到 none。 我从数据库中删除了所有表并且 运行 "grails dbm-update" 然后它创建所有表,但不创建我添加到 "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'
}
}
我的项目现在完全停滞了。
您创建视图的语法不正确,在字符串前面添加 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'
)