Grail data-migration-plugin

时间:2017-03-20 12:36:22

标签: grails data-migration

我按照此链接的说明进行操作 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 for development 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'
    }
}

我的项目现在完全停滞不前。

1 个答案:

答案 0 :(得分:1)

您的create view语法不正确在字符串前面添加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'
               )