spring - 升级到grails 3后,grails数据库迁移插件问题

标签 spring grails migration liquibase

我使用了较早版本的grails-database-migration插件已有一段时间,但从未遇到过任何大问题。但是,最近我将整个项目升级到grails 3.0.9,并进行了一些其他开发,其行为如下:

  • 将当前的prod数据库结构导入本地计算机(该数据库副本没有最新更改和新实体)
  • 执行: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)


    这是我的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'
    }
    

    更新
    我有另一种方法来解决此问题:
    我的计划是根据当前的产品数据库生成一个变更日志,然后为所做的更改生成差异。听起来简单明了;但是,它没有按预期进行。这是我所做的:
  • 转储产品数据库
  • 删除了liquibase表
  • 运行: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/

    相关文章:

    spring - spring webflux 中的文件上传 - 所需的 MultipartFile 参数 'file' 不存在

    java - 使用 Spring Boot 和 Executors 进行异步操作

    java - Spring Boot gRPC : How to return error code when business error happens?

    grails - 排除 Grails 构建范围依赖项

    linux - Perforce:从 Windows 到 Linux 的交叉迁移无法重放检查点

    java - 如何在 Swagger 中描述多态端点?

    tomcat - 作为 war 运行时将目录添加到 grails 类路径中?

    sql-server - 使用可信连接将 Grails 连接到 MS SQL

    mysql - 如何从适用于 OpenVMS 的 Oracle RDB 迁移到 Windows 中的 MySQL?

    php - 如何修复错误 "Fatal error: Uncaught --> Smarty: unable to write file"?